Berkeley Socket Abstraction Tom Skoczlas
History Created at UC Berkeley for use on UNIX Provides an API for which to “abstract” TCP/IP communication “adopted” by Microsoft and renamed Winsock
Client-Server Model In software, it’s all client-server. Application Layer Protocol describes the way client and server programs communicate
TCP vs UDP sockets TCP Sockets – Connection-oriented. Idea of a “stream” UDP Sockets- Connection-less. One transmittion per send operation
Stateful vs Stateless Servers Stateful – A server that keeps an active record of the communication. Example - Telnet Stateless – A server that keeps no record of the communication Example- Web (in general terms)
Client Algorithm (TCP) Find IP and port of server Allocate a Socket Specify an unused port Communicate with the Server Close Connection
Client Functions (TCP) socket() connect() send() recv() closesocket()
Server Algorithm (TCP) Create a socket and bind it to a port. Place the socket in passive mode. Accept the incoming connection. Repeatedly receive a request, formulate and send back a response. When finished, close the connection and return to “acceptive” state.
Server Functions (TCP) socket() bind() listen() accept() recv() send() closesocket()
UDP differences Client – can “skip” the connect() call. In this case the sendto() function is used, and the endpoint must be specified each time Server – server is always receiving, since there is no “connection” No call to listen() or accept()
Concurrent vs Iterative Servers Iterative: Block on I/O operations Concurrent: Allow multiple I/O operations at once Possible through: Multiple Threads Multiple Processes Software Polling
Winsock differences Winsock requires the use of the Winsock dynamically-linked library. Requires use of WSAstartup() and WSAcleanup to initialize and uninitialize the dll
Questions? Good reference – Internetworking with TCP/IP, VOL. 3: Client-Server Programming and Applications Comer & Stevens