是什么
Transmission Control Protocol (TCP) 传输控制协议。是基于IP网络,通过建立连接,来传输数据的协议;它能确保数据包以正确的顺序送达。
TCP sockets (套接字)
也叫(virtual ports)虚拟端口,在TCP连接中用来标识 端-到-端 的唯一连接,在连接过程中不会改变。
IP地址+端口号 构成一个端,合起来,连接的两端就构成一个套接字(socket)
3 way handshake(3次握手) - 建立连接
TCP基于IP网络建立连接的过程,即:SYN – SYN-ACK – ACK
客户端 服务端
Active open | | Passive open
SYN-SENT | --------------SYN=1 seq=x-----------> | SYN-RCVD
SYN-SENT | <····ACK=1 SYN=1 seq=y ack=x+1 ······ | SYN-RCVD
ESTABLISHED | --------ACK=1 seq=x+1 ack=y+1-------> | ESTABLISHED
# SYN: Synchronize
# ACK: Acknowledgment
# seq: initial sequence number (ISN)
# ack: acknowledgment number
4次挥手 - 断开连接
即:FIN – ACK – FIN – ACK
客户端 服务端
Active close | | Passive close
ESTABLISHED | --------------FIN=1 seq=u-----------> | ESTABLISHED
FIN_WAIT_1 | <······ ACK=1 seq=w ack=u+1 ········· | CLOSE-WAIT
FIN_WAIT_2 | <·····FIN=1 ACK=1 seq=v ack=u+1 ····· | LAST-ACK
TIME-WAIT | -------ACK=1 seq=u+1 ack=v+1--------> | CLOSED
CLOSED |
参考
TCP的三次握手与四次挥手
TCP 3-way handshake
TCP Connection Termination
网友评论