1. Introduction

We, as humans, have several different ways to start a conversation. But, in general terms, any conversation starts with one person demonstrating his own intention to talk. The other person, in turn, returns with interest — or not — in having a conversation, and then the dialogue can go on.

The process to initiate a connection between machines connected in a network is not so different. We have multiple protocols that enable machines to communicate. Some of them are very straightforward to start a communication, such as UDP. Others require a handshaking process, such as TCP.

In the TCP scenario, a machine introduces by requesting a connection. This process involves several tasks actively triggered and passively responded to by the involved machines.

In this tutorial, we’ll study the role of active and passive machines in creating TCP connections. First, we’ll have a brief review of TCP connections. Thus, we’ll in-depth inspect the actions of active and passive machines in opening TCP connections. Next, we’ll see possible connection opening problems that can occur due to the wrong actions of the passive/active machines. Finally, we conclude the article with a systematic summary.

2. A Brief Review of TCP Connections

TCP is a connection-oriented protocol. It means that the involved machines must create a connection before exchanging data. Opening a TCP connection includes exchanging control messages between the machine that starts and the machine that waits for a communication.

This opening connection process, in TCP, consists of a three-way handshake. In summary, the handshake process uses SYN and ACK messages to establish communication between a TCP client and a TCP server.

First, the server sends an SYN message to the server. Then, if the server is available, it responds to the client with an SYN-ACK. Thus, the client confirms the SYN-ACK by sending an ACK to the server. Finally, the connection is established, and the machines can exchange data.

The following image demonstrates the three-way handshaking process:

THW2

3. Active and Passive Opening of TCP Connections

The client/server model is the base of TCP/IP. In this way, opening a TCP connection embraces multiple operations for the client and the server. Relevant operations executed by the clients and servers (or both) after creating a socket are described next:

  • Bind: an operation to assign an IP address and port number to a socket. The server-side socket is necessarily explicitly bound to an address and port. Explicitly binding the client-side socket, however, is optional
  • Listen: an operation to configure the server-side socket into a connection mode. It defines, for example, how many connections a socket will support in its listening queue
  • Accept: an operation that makes the server-side socket accept the first request in its connection queue. So, it triggers the process to create a connection between a server and client on the server-side
  • Connect: an operation executed on the client-side that sends a connection request to a given TCP/IP server

We can note the execution of different operations in the server-side and client-side to open a TCP connection. Thus, we can assume that the client and server play different roles in this context. These different roles are what define an active or passive opening of TCP connections:

  • Active: the client is responsible for the active opening of a TCP connection. It means that the client must pro-actively send a connection request (SYN) to an already known server (IP and port) using the connect operation
  • Passive: the server is in charge of the passive opening of TCP connections. Thus, the server waits for requests (SYN) from the client using the accept operation. To actually accept a connection, the server must respond in previously defined IP and port (bind) and have slots to hold new connections (listen)

The following image demonstrates the active and passive TCP connection opening:

ActivePassive

3.1. Transmission Control Blocks

Regardless of passively or actively opening a TCP connection, clients and servers use a Transmission Control Block (TCB) to keep relevant data about the connection.

The TCB on the client-side is quite simple. Since the client already knows his own address and must know the server address to create the connection actively, he can directly define the TCB through this pair of addresses.

The TCB on the server-side is more complex. Since the server executes a passive connection opening, two scenarios are possible: the server accepts any connection request, or the server accepts only connection requests of specific clients.

In the first scenario, the server creates the TCB without the client address or socket number. So, this information is bound to the TCB when the client actively requests the connection. In the second scenario, the server already knows the client address and can identify the connection requests to accept only those expected.

4. Potential Connection Problems

Different problems can occur while opening a TCP connection. These problems are mostly related to errors during the transmission of SYN and ACK messages. Let’s see a little bit more about some of them:

  • Failed Connection Attempts: this problem happens when a socket sending or receiving an SYN packet goes to an uncommon state during the connection. It occurs, for example, when a client in SYN_SENT state (waiting for the server’s SYN-ACK) receives an RST message
  • Bad Segments Received: this problem occurs in several situations when requests are corrupted or spoofed. For instance, if the server receives a probably spoofed SYN request, it is understood as a bad segment, and the challenge ACK mitigation strategy is employed

5. Systematic Summary

We studied the active and passive connection opening in TCP. We saw that these connection opening roles are intrinsic related to the server/client model that bases the TCP/IP.

In summary, the client is responsible for actively requesting a connection to a server. The operation connect triggers this request by sending an SYN message to an already known server address (IP and port).

The server, in turn, passively waits for connection requests. It is done by executing the operation accept. However, before executing this operation, the server must bind to an address and define the number of connections it will support.

The following table summarizes the characteristics of the active and passive connection openings in TCP:

Active Passive
Client/Server Model Client Server
General Concept Request for connection Wait for a connection request
Typical Operations connect bind, listen, accept
Transmission Control Block Requires both client and server addresses Requires at least the server address

6. Conclusion

In this article, we learned about active and passive TCP connections opening. First, we reviewed the TCP protocol, focusing on the establishment process of TCP connections. So, we in-depth studied the concepts of active and passive TCP connection opening. We also investigated potential connection problems in TCP. Finally, we summarized all the studied concepts in a systematic summary.

We can conclude that the passive and active roles to open a TCP connection are fully compliant with the client/server model that bases TCP. In this way, it successfully enables several clients to connect with available servers on-demand and at any moment to execute their tasks.