1

We know TCP socket is port numbers and IP addresses. Is TCP socket connection is 3-way handshake:the SYN packet, the SYN-ACK packet, and the ACK packet?

Is TCP socket connection follows TCP stack?

And is TCP connection follows the TCP stack for data transmission?

My question is how TCP stack, TCP connection and TCP socket connection are interrelated? And how could we differentiate them? And socket connection uses IP address at later that is responsible by OS?

1 Answer 1

2

A TCP connection is identified by a pair of sockets (local and remote). Connecting to a remote TCP and handshaking gives you a bidirectional connection. It is like a pair of pipes (one in each direction) between the hosts, and anything going in one end of a pipe comes out the other end.

RFC 793, Transmission Control Protocol explains (see highlights, but the RFC goes into much more detail):

Multiplexing:

To allow for many processes within a single Host to use TCP communication facilities simultaneously, the TCP provides a set of addresses or ports within each host. Concatenated with the network and host addresses from the internet communication layer, this forms a socket. A pair of sockets uniquely identifies each connection. That is, a socket may be simultaneously used in multiple connections.

The binding of ports to processes is handled independently by each Host. However, it proves useful to attach frequently used processes (e.g., a "logger" or timesharing service) to fixed sockets which are made known to the public. These services can then be accessed through the known addresses. Establishing and learning the port addresses of other processes may involve more dynamic mechanisms.

Connections:

The reliability and flow control mechanisms described above require that TCPs initialize and maintain certain status information for each data stream. The combination of this information, including sockets, sequence numbers, and window sizes, is called a connection. Each connection is uniquely specified by a pair of sockets identifying its two sides.

When two processes wish to communicate, their TCP's must first establish a connection (initialize the status information on each side). When their communication is complete, the connection is terminated or closed to free the resources for other uses.

Since connections must be established between unreliable hosts and over the unreliable internet communication system, a handshake mechanism with clock-based sequence numbers is used to avoid erroneous initialization of connections.

12
  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Ron Maupin
    Apr 11 at 14:40
  • 2
    The three-way handshake uses the sockets, and it creates a connection (or fails) in the end. A socket is created when an application requests it of TCP.
    – Ron Maupin
    Apr 11 at 14:47
  • 2
    No, the sockets exist before the connection. A connection requires sockets in order for the connection to be created. Again, it is explained in the RFC. It explains passive and active Opens for sockets. A application must create a socket to send a SYN, and if the socket to which it is trying to connect on the remote host does not already exist, the remote TCP will refuse the connection request.
    – Ron Maupin
    Apr 11 at 15:16
  • 1
    "If the socket to which it is trying to connect on the remote host does not already exist, the remote TCP will refuse the connection request." Sockets must already exist on both sides before a connection can be created.
    – Ron Maupin
    Apr 11 at 15:25
  • 1
    The socket is created when an application asks TCP to create one, either with a specific port number, or with Port 0 that tells TCP to give it an ephemeral port. Again, this is all detailed in the RFC.
    – Ron Maupin
    Apr 11 at 15:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.