News
12th July 2015 | By:

TCP Socket States

Sockets are a way of opening a full duplex communication between two end points, in order to open the communication certain negotiation is required between the both parties, this negotiation is done by
sending a special crafted packet with to indicate the different states. The Socket states indicate the current state in which the socket is in, this tutorial assume a basic knowledge of *BSD sockets.

There are several socket states.

LISTEN
Indicates that the socket is in listening mode and is ready to accept a new connection.

SYN_SENT
The client sent the syncronous request and is waiting for a response from the server.

ESTABLISHED
At this stage both ends are ready to send data, the data can flow both ways (full duplex).

FIN_WAIT_1
The remote host wants to close the connection, the client will will be in this state.

FIN_WAIT_2
This is similar to FIN_WAIT_1 but is sort of grace

CLOSE_WAIT
The client wants to close the connection

CLOSING
This state indicates that the connection is being dropped and is waiting for the acknolegment from the server

CLOSED
This state is the default state when no new connection is established, each connection will start with this state. This also means the connection is completelyt closed and acknoledged

Here is an example of a full TCP socket transition from CLOSED->ESTABLISHED->DATA TRANSFER->CLOSED


tcp-socket-state-example

References:
Header file of default states: http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/include/net/tcp_states.h?id=HEAD#n16
Description of TCP states: http://www.cs.northwestern.edu/~kch670/eecs340/proj2-TCP_IP_State_Transition_Diagram.pdf
TCP man page: https://www.freebsd.org/cgi/man.cgi?query=tcp&apropos=0&sektion=4&manpath=FreeBSD+11-current&arch=default&format=html

Tags: , , , ,

Leave a reply

Your email address will not be published. Not now, not ever. Required fields are marked *

Comments


You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Name
Email
Website