Socket Intro

Note on 17 Jul 2002

Sockets

  • Sockets are the method by which & network application sends and receives data.
  • Socket applications use ports to determine what application handles a given message
  • Information can be sent to and fro by writing to and reading from the socket. 


Ports

Data Port# > TCP/UDP > # > Application

TCP & UDP


  • TCP (Transport Control Protocol)
    • Commonest internet protocol
    • Provides guaranteed connection-oriented communication
    • Normally 2 types, server & client
  • UDP (Universal Datagram Protocol)
    • Provides connectionless, unguaranteed communication
    • Faster than TCP

TCP - client side

  1. Open a socket
  2. Open input and output streams to the socket
  3. Do any necessary reads and writes to the sockets
  4. Close the streams
  5. Close the socket

TCP - server side

  1. Open server socket
  2. Listen for communication
  3. When communication occurs, create new socket to deal with it
  4. Communication on new socket
  5. Close new socket
  6. goto 2

TCP - multithreadded server

  • 1. Create & bind socket
  • 2. Accept requcata & create child to handle new socket
    • Goto 1
    • 3. Communicate
  • 4. Close socket & kill child

UDP

  • sending
    • Create UDP socket
    • Create UDP packet
    • Send UDP packet
    • Close UDP socket
  • receiving
    • Create UDP socket
    • Listen for data
    • Receive UDP packet
    • Gto 2


Comments

Popular posts from this blog

The Network Layer

The Transport Layer