Detecting TCP Client Disconnect

In TCP there is only one way to detect an orderly disconnect, and that is by getting zero as a return value from read()/recv()/recvXXX() when reading. There is also only one reliable way to detect a broken connection: by writing to it. After enough writes to a broken connection, TCP will have done enough retries … Read more

What is the theoretical maximum number of open TCP connections that a modern Linux box can have

A single listening port can accept more than one connection simultaneously. There is a ’64K’ limit that is often cited, but that is per client per server port, and needs clarifying. Each TCP/IP packet has basically four fields for addressing. These are: source_ip source_port destination_ip destination_port <—– client ——> <——— server ————> Inside the TCP … Read more

What does “connection reset by peer” mean?

It’s fatal. The remote server has sent you a RST packet, which indicates an immediate dropping of the connection, rather than the usual handshake. This bypasses the normal half-closed state transition. I like this description: “Connection reset by peer” is the TCP/IP equivalent of slamming the phone back on the hook. It’s more polite than … Read more