Network-3-Socket Programming
Socket programming
- goal: learn how to build client/server applications that communicate using sockets
- socket: door between application process and end-end-transport protocol
- Two socket types for two transport services
- UDP : unreliable datagram
- TCP : reliable, byte stream-oriented
- Application Example
- client reads a line of characters (data) from its keyboard and sends data to server
- server receives the data and converts characters to uppercase
- server send modified data to client
- client receives modified data and displays line on its screen
Socket programming with UDP
- UDP: no “connection” between client & 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
Client/server socket interaction: UDP
Example app: UDP client
Example app: UDP server
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 userd to distinguish clients
- application viewpoint
- TCP provides reliable, in-order byte-stream transfer (“pipe”) between cient and server
Client/server socket interaction: TCP
Example app: TCP client
Example app: TCP server
연결을 담당하는 serverSocket 1개와 각 연결이 완료되면 요청마다 처리를 담당하는 connectionSocket이 생성된다
참조
- 컴퓨터 네트워크 이미정 교수님 강의
- Computer Networking: A Top-Down Approach Featuring the Internet