TCP sockets

TCP sockets are divided into three.

The reason is because TCP is a connection oriented protocol.

 

Listener socket

 

This socket is used to accept incoming connections:

 

  1. The socket is binded to an address and port.

  2. The socket calls listen telling the OS it's ready to receive connections.

  3. The socket receive indication per incoming connection (for asynchronious sockets).

  4. The socket accepts the connection, receiving the handle of the new socket (that represents the new connection)

 

Server's client connection

 

This socket represents the incoming connection made to the server, and it's acting just like a regular socket.

 

Client socket

 

This socket is used to make outgoing connections:

 

  1. The socket may be binded. (if not the OS decides which network interface to use)

  2. The socket is trying to connect to a remote host.

  3. The socket will receive an event of success or failure.