Socket Programming
goal: learn how to build client/server applications that communicate using sockets
socket: door between applications process and end-end-transport protocol
Two socket types for two transport services:
Socket programming with UDP
UDP: no “connection” between client and server:
- no handshaking before sending data
- sender explicitly attaches IP destination address and port # to each packet
- receiver extracts sender IP address and port# from received packet
UDP: transmitted data may be lost or received out-of-order
Application viewpoint:
- UDP provides unreliable transfer of groups of bytes (“datagrams”) between client and server processes
Socket programming with TCP
Client must contact server
- server process must first be running
- server must have created socket (door) that welcomes client’s contact
Client contacts server by:
- Creating TCP socket, specifying IP address, port number of server process
- when client creates socket: client TCP establishes connection to server TCP
- when contacted by client, server TCP creates new socket for server process to communicate with that particular client
- allows server to talk with multiple clients
- source port numbers used to distinguish clients (more in Chap 3)
Application viewpoint
TCP provides reliable, in-order byte-stream transfer (“pipe”) between client and server processes.