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 > # > ApplicationTCP & 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
- Open a socket
- Open input and output streams to the socket
- Do any necessary reads and writes to the sockets
- Close the streams
- Close the socket
TCP - server side
- Open server socket
- Listen for communication
- When communication occurs, create new socket to deal with it
- Communication on new socket
- Close new socket
- 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
Post a Comment