TCP state transmissions

For every instance of a kind of item, in a specific period of time, the instance itself will stay in a specific status. Take a cell phone as example, it can be in IDLE status, ALERTING status, CONNECTED status etc. A process could be in CREATED, READY, BLOCKED, RUNNING, DEAD status. When specific events occur, the status of the item can be transfer from one to another. For a kind of items, we can talk about different kind of status from different point of view, or different dimensions. I notes the transmissions of TCP endpoints in this one.

State transmission chart

People usually use a state transmission diagram to describe the state transfermations of an item. Before sketching a diagram, there are something should be clarified. We must tell explicitly the item that we need to describe, list all the states during the whole transformation and the events that triger the transfermation. I still take the celll phone as example. The phone is the object which has IDLE, SHUTDOWN, ALERTING, CONNECTED states, the events trigering the transmission are shown with arrows.

TCP endpoints state transmission

TCP protocal discribe the communication from endpoint to endpoint. The tcp state tranmission diagram describe the endpoints’ state change. It actually the transmission ctronl block in the os kernel (in most conditions), from the application layer, we can treat it as the socket state transfermation. Let’s review a whole process of a tcp segment sending and receiving, the connection is initiated with 3 segments, then established, and shut down with 4 segments(normally). For each endpoint, as the tcp segment’s sending and receiving, the state is changing. I presume there’s no exception during the communication, and the change will be as following,

The initial state for each points is CLOSED. After the server calls the function Accept(), and the state changes from the CLOSED to LISTEN, and stay in the LISTEN until a SYN from client is received. Sometime later, A client sends a [1.SYN] to request a connection. The state of the client tansmits from CLOSED to SYN_SENT, here, the client keeps wating for the end of the 3-way-handshake. After the [1.SYN] is received by the server, it will become SYN_RECEIVED, and responses with a [2.SYN,ACK], to answer the [1.SYN], and at the same time to request a connection from server to client. The client answers a [3.ACK], both of the endpoints become ESTABLISHED state, a connection has been established, the application layer data is sent back and forth.

When either endpoint requires to cut the established connection, it will send a FIN, say, the client sends a [8.FIN] to finish the connection (Maybe the server initiate the release procedure), this action will drive the client going to the state FIN_WAIT_1, in which the client keeps waiting for the ACK from the counter point. The server side gets the [8.FIN], notices that there will be no more data from the client side. Server answers the [8.FIN] with an [9.ACK], transfer to the CLOSE_WAIT state to wait for the server application layer finishing sending application data. After getting the [9.ACK], client transfers from FIN_WAIT_1 to FIN_WAIT_2. In FIN_WAIT_2, the client is receiving data only, but will never send anything until the server sends a FIN. At last, the server sends a [10.FIN], the server waits for the lask ACK from the client, this state is LAST_ACK. The client acknowledges the [10.FIN] with [11.ACK] as known as the last ACK, and goes to the TIME_WAIT state. The server goes to the CLOSED state after getting the last ACK. After the TIME_WAIT timeouts, the client goes to the CLOSED state.

When we combine the state tranfermation diagram, we get the one descripted in RFC793.

TCP abnormal endpoints state transmission

When we consider the RST segment, e.g. the client requests a connection to the server port, on which there’s no processing listening, the server answers with a RST, RST makes the client transfering to the CLOSED state.

TCP simultaneous established connection

When the endpoints request a connection to each other simultaneously. It’s acting like this, there’s no client or server now, they are both clients, or servers.

State diagram,

TCP simultineous shutdown connection

Shutdown a connection simultineously on both sides.

Sometimes, FIN and ACK are combined to send together. In this situation, there’s no CLOSING state.

State diagram.

Integrated TCP endpoints state transmission

When we comblie above state transmission diagrams in different situation, we get a final version.