Kaigai Blog living abroad in my twenties

【My Study Note】TCP Socket States

Infotech Networking

TCP Socket States


A socket is the instantiation of an end-point in a potential TCP connection. An instantiation is the actual implementation of something defined elsewhere.

TCP sockets require actual programs to instantiate them. You can contrast this with a port which is more of a virtual descriptive thing. In other words, you can send traffic to any port you want, but you’re only going to get a response if a program has opened a socket on that port.

TCP sockets can exist in lots of states.

Listen

Listen means that a TCP socket is ready and listening for incoming connections. You’d see this on the server side only.

SYN_SENT

This means that a synchronization request has been sent, but the connection hasn’t been established yet. You’d see this on the client side only.

SYN_RECEIVED

This means that a socket previously in a listener state, has received a synchronization request and sent a SYN_ACK back. But it hasn’t received the final ACK from the client yet. You’d see this on the server side only.

ESTABLISHED

This means that the TCP connection is in working order, and both sides are free to send each other data. You’d see this state on both the client and server sides of the connection.

FIN_WAIT

This means that a FIN has been sent, but the corresponding ACK from the other end hasn’t been received yet.

CLOSE_WAIT

This means that the connection has been closed at the TCP layer, but that the application that opened the socket hasn’t released its hold on the socket yet.

CLOSED

This means that the connection has been fully terminated, and that no further communication is possible.

Additional Info

There are other TCP socket states that exist. Additionally, socket states and their names, can vary from operating system to operating system.

That’s because they exist outside of the scope of the definition of TCP itself. TCP, as a protocol, is universal in how it’s used since every device speaking to TCP protocol has to do this in the exact same way for communications to be successful.

However, choosing how to describe the states of a socket at the operating system level isn’t quite as universal.