High Level Socket API Dr Sanjay P Ahuja

  • Slides: 8
Download presentation
High Level Socket API Dr. Sanjay P. Ahuja, Ph. D. 2010 -14 FIS Distinguished

High Level Socket API Dr. Sanjay P. Ahuja, Ph. D. 2010 -14 FIS Distinguished Professor of Computer Science School of Computing, UNF

The Client-Server Model l An application that initiates communication is a client. A server

The Client-Server Model l An application that initiates communication is a client. A server is any program that waits for incoming communication requests from a client. Standard client programs included with TCP/IP software include telnet client, SSH client, email client, ftp client etc. The client-server model involves requests and replies.

Types of Servers: Connectionless vs. Connection-Oriented servers l If client and server communicate using

Types of Servers: Connectionless vs. Connection-Oriented servers l If client and server communicate using User Datagram Protocol (UDP), the interaction is connectionless. If they use Transmission Control Protocol (TCP), the interaction is connection-oriented. l TCP provides the reliability needed to communicate across the Internet. l It retransmits segments that do not arrive correctly at the destination l It uses checksum to ensure data received is not corrupted during transmission l It uses sequence numbers to ensure data arrives in order etc. l UDP provides “best-effort” service and does not guarantee reliable delivery. l It is suited to real-time, audio/video streaming traffic.

Types of Servers: Iterative vs. Concurrent servers l An iterative server will service one

Types of Servers: Iterative vs. Concurrent servers l An iterative server will service one client request before moving onto the next request. In this scenario, queues can build up. l A concurrent server will spawn a new (child) process (or thread) to service a client request and itself listen for the next client connection. This generally provides quicker response time. l Server software must be explicitly programmed to handle concurrent client requests because multiple clients contact a server using its single, well-known protocol port. l The fork() function call is used to create a new process in UNIX/Linux. This call causes the O/S to make a copy of the executing program and allows both copies to run at the same time. The call returns a finite value (process ID# of child process) to the calling (parent) process and a value of 0 to the child process.

Types of Servers: Iterative vs. Concurrent servers

Types of Servers: Iterative vs. Concurrent servers

The Socket API l TCP/IP software reside in the O/S. So application programs need

The Socket API l TCP/IP software reside in the O/S. So application programs need to interact with the O/S to use TCP/IP to communicate. The routines provided by the O/S defines the API. l The Socket Interface from UC Berkeley is such an interface for the BSD UNIX O/S for application programs to interact with the TCP/IP software residing in the O/S. l A socket is one end-point of a two-way communication link between two programs running on the network. l TCP/IP protocols define a communication endpoint to consist of an IP address and a protocol port number.

Outline for typical concurrent servers int pid, s, conn; S = Socket(. . );

Outline for typical concurrent servers int pid, s, conn; S = Socket(. . ); // fill in server address Bind(s, . . ); Listen(s, LISTNQ); while(1){ conn = Accept(s, . . ); //blocking call if( (pid = fork()) ==0) { close (s); //child closes listening socket doit( conn); //service request close(conn); exit(0); //child exits } // end of if close(conn); //parent closes connected socket }// end of while loop