The following steps describe a TCP connection process using sockets.
- Server Creates Socket and Listens
- Client Creates a Socket and Connects
- Transport Layer Delivers Message to Server
- Server Creates Socket & Process
- Transport Layer Delivers Message to Client
- Sockets Closed
1 Server Creates Socket and Listens
A web server creates a socket dedicated to listening for client requests. After the socket exists, the server goes into “listening” mode and waits for a client's request. It periodically checks for messages received in this socket.
This type of socket is referred to as a connectionless socket. A connectionless socket is used to establish a TCP connection with the HTTP server. There is no destination IP address or port number defined for this type of socket.
2 Client Creates a Socket and Connects
When a client wants to download a web page it creates a socket then sends the web page download request to the socket.
3 Transport Layer Delivers Message to Server
The client’s Transport layer periodically checks its transmit buffers to determine if a message needs to be sent. When a message is found it is forwarded to the destination address.
4 Server Creates Socket & Process
When the server receives the client’s request, it creates a new dedicated socket and process. It then creates a message for the client and sends it to the socket.
Note this socket uses the client’s destination IP address and port number. This virtual TCP connection is now referred to as “established”.
The message sent by the server is the HTML file for the requested webpage.
5 Transport Layer Delivers Message to Client
The server’s Transport layer periodically checks its transmit buffers to determine if a message needs to be sent.
When a message is found it is forwarded to the destination address.
6 Sockets Closed
After the client receives the web page it requested, it sends an acknowledge to the server then closes its socket.
The server receives the client’s acknowledge then closes its socket.