Socket programming

  • goal: learn how to build client/server applications that communicate using sockets
  • socket: door between application process and end-end-transport protocol
스크린샷 2021-08-10 오후 1 56 42
  • Two socket types for two transport services
    • UDP : unreliable datagram
    • TCP : reliable, byte stream-oriented
  • Application Example
    1. client reads a line of characters (data) from its keyboard and sends data to server
    2. server receives the data and converts characters to uppercase
    3. server send modified data to client
    4. 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

스크린샷 2021-08-10 오후 2 07 36

Example app: UDP client

스크린샷 2021-08-10 오후 2 09 01

Example app: UDP server

스크린샷 2021-08-10 오후 2 10 30

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

스크린샷 2021-08-10 오후 2 21 11

Example app: TCP client

스크린샷 2021-08-10 오후 2 23 25

Example app: TCP server

스크린샷 2021-08-10 오후 2 26 56

연결을 담당하는 serverSocket 1개와 각 연결이 완료되면 요청마다 처리를 담당하는 connectionSocket이 생성된다

참조

  • 컴퓨터 네트워크 이미정 교수님 강의
  • Computer Networking: A Top-Down Approach Featuring the Internet