A article about connection and socket

A article about connection and socket

In the TCP/IP protocol, a connection is usually composed of two sockets, one is the client socket and the other is the server socket.

When a client wants to establish a connection with a server, it first creates a socket and specifies the IP address and port number of the server to be connected, and then sends a connection request to the server through this socket. The server's socket listening on the specified port will receive the connection request and create a new socket to establish a connection with the client's socket. In this process, both the client and the server will have a socket for communication in the connection.

Once the connection is established, the client and server can exchange data through their respective sockets. During the communication process, each socket has a unique identifier, which consists of a four-tuple (source IP address, source port number, destination IP address, destination port number). This four-tuple can uniquely identify a TCP connection.

Therefore, a TCP connection is usually composed of two sockets, each with its own unique identifier. The client's socket and the server's socket play different roles, and they can communicate with each other after the connection is established.

In Linux systems, the following two parameters affect the number of TCP connections:

  1. net.core.somaxconn: This parameter is used to control the length of the waiting queue for each listening socket (such as the server socket). In Linux 2.6 and later versions, the default value is 128, and the maximum value is the value specified by /proc/sys/net/core/somaxconn. However, it should be noted that even if a large waiting queue is set, it is not necessarily guaranteed that the system can accept and process so many connection requests.

In the TCP/IP protocol, when a client sends a connection request to a server, the server's listening socket will accept the request and establish a new connected socket for communication with the client. However, if the server cannot process the connection request in time, the connection request will be placed in the socket waiting queue and wait for the server to process it.

The socket waiting queue is a first-in-first-out queue that stores connection requests that have completed the three-way handshake but have not yet been accepted by the server. Each listening socket has its own waiting queue to store connection requests from different clients. When a connection request arrives at the server, it will first be added to the corresponding listening socket's waiting queue, waiting for the server to accept the connection.

The length of the waiting queue is controlled by kernel parameters, such as the net.core.somaxconn parameter in Linux, which is used to control the length of the waiting queue for each listening socket. When the waiting queue is full, new connection requests will be rejected, which means that the client cannot establish a connection.

  1. net.ipv4.tcp_max_syn_backlog: This parameter is used to control the length of the SYN queue in the TCP three-way handshake, that is, the half-connection queue. In Linux 2.2 and later versions, the default value is 128 and the maximum value is 65536. If the SYN queue is full, new connection requests will be rejected. However, it should be noted that the length of the SYN queue is only the length of the half-connection queue, which is not equal to the number of TCP connections that the system can handle simultaneously.

Therefore, the maximum number of TCP connections allowed depends on multiple factors such as system memory, current kernel parameter configuration, and network bandwidth.

<<:  5G will bring a range of possibilities to future buildings

>>:  Static routing or dynamic routing, an example to make it clear!

Recommend

Space Data-as-a-Service Ready to Take Off

【51CTO.com Quick Translation】The upcoming commerc...

How does TCP ensure reliable transmission?

There are many factors in the network that may ca...

The battle of data center network switching equipment architecture

Switching technology is one of the important tech...

Ethernet Adapter Market to See Record Revenue Growth in 2022

According to a recent report released by DellOro ...

The love-hate relationship between TCP and UDP

Recently, the epidemic in Qiaoxi District, Shijia...

What is structured cabling? What are the benefits of structured cabling?

In the world of cabling, the term structured cabl...

BuyVM Las Vegas VPS simple test

BuyVM has been shared many times in the blog. It ...

What was the Internet like 20 years ago? Reminiscing about the Internet's heyday

For the younger generation, they are born in a ma...

How can operators make full use of SDN?

When talking to communications service providers ...