分类: LINUX
2016-08-08 23:43:11
查看内核源代码中的定义
net/ipv4/tcp.c
/*
Description of States:
*
* TCP_SYN_SENT
sent a connection request, waiting for ack
*
* TCP_SYN_RECV
received a connection request, sent ack,
* waiting for final ack in three-way handshake.
*
* TCP_ESTABLISHED
connection established
*
* TCP_FIN_WAIT1
our side has shutdown, waiting to complete
* transmission of remaining buffered data
*
* TCP_FIN_WAIT2
all buffered data sent, waiting for remote
* to shutdown
*
* TCP_CLOSING
both sides have shutdown but we still have
* data we have to finish sending
*
* TCP_TIME_WAIT
timeout to catch resent junk before entering
* closed, can only be entered from FIN_WAIT2
* or CLOSING. Required because the other end
* may not have gotten our last ACK causing it
* to retransmit the data packet (which we ignore)
*
* TCP_CLOSE_WAIT
remote side has shutdown and is waiting for
* us to finish writing our data and to shutdown
* (we have to close() to move on to LAST_ACK)
*
* TCP_LAST_ACK
out side has shutdown after remote has
* shutdown. There may still be data in our
* buffer that we have to finish sending
*
* TCP_CLOSE
socket is finished
*/
tcp客户端connect发起之后,协议栈就会发送SYN给服务器
协议栈收到来自服务器的响应后,发出Ack后,就进入了established
tcp服务器在收到SYN后,发送SYN+ACK后就进入SYN_RECVD,再次收到客户端的Ack时,也进入established
可见established状态连接的双方进入的时机是有先后的,客户端是先进入的,服务器是后进入的