浅谈tcp的半打开连接( 三 )


使用tcpdump抓去第三个nc客户端的tcp包:
zuchunlei@box:~$ sudo tcpdump -i any tcp port 10000 -nntcpdump: verbose output suppressed, use -v or -vv for full protocol decodelistening on any, link-type LINUX_SLL (Linux cooked), capture size 262144 bytes21:21:47.357226 IP 127.0.0.1.36520 > 127.0.0.1.10000: Flags [S], seq 1445936074, win 43690, options [mss 65495,sackOK,TS val 4214107076 ecr 0,nop,wscale 7], length 021:21:48.358267 IP 127.0.0.1.36520 > 127.0.0.1.10000: Flags [S], seq 1445936074, win 43690, options [mss 65495,sackOK,TS val 4214107327 ecr 0,nop,wscale 7], length 021:21:50.373837 IP 127.0.0.1.36520 > 127.0.0.1.10000: Flags [S], seq 1445936074, win 43690, options [mss 65495,sackOK,TS val 4214107831 ecr 0,nop,wscale 7], length 021:21:54.565832 IP 127.0.0.1.36520 > 127.0.0.1.10000: Flags [S], seq 1445936074, win 43690, options [mss 65495,sackOK,TS val 4214108879 ecr 0,nop,wscale 7], length 021:22:02.758111 IP 127.0.0.1.36520 > 127.0.0.1.10000: Flags [S], seq 1445936074, win 43690, options [mss 65495,sackOK,TS val 4214110927 ecr 0,nop,wscale 7], length 021:22:18.885934 IP 127.0.0.1.36520 > 127.0.0.1.10000: Flags [S], seq 1445936074, win 43690, options [mss 65495,sackOK,TS val 4214114959 ecr 0,nop,wscale 7], length 021:22:51.141643 IP 127.0.0.1.36520 > 127.0.0.1.10000: Flags [S], seq 1445936074, win 43690, options [mss 65495,sackOK,TS val 4214123023 ecr 0,nop,wscale 7], length 0可以看到客户端在进行超时重传SYN段的过程中,服务端没有发送一个包 。
在客户端SYN_SENT超时后,使用netstat查看10000端口状态:
Every 1.0s: sudo netstat -tnpoa|sed -n -e 2p -e /10000/pSat Dec 16 21:27:36 2017Proto Recv-Q Send-Q Local AddressForeign AddressStatePID/Program name Timertcp00 0.0.0.0:100000.0.0.0:*LISTEN2022/pythonoff (0.00/0/0)tcp00 127.0.0.1:36516127.0.0.1:10000ESTABLISHED 2347/ncoff (0.00/0/0)tcp00 127.0.0.1:10000127.0.0.1:36518ESTABLISHED -off (0.00/0/0)tcp00 127.0.0.1:36518127.0.0.1:10000ESTABLISHED 2388/ncoff (0.00/0/0)tcp00 127.0.0.1:10000127.0.0.1:36516ESTABLISHED -off (0.00/0/0)客户端连接消失 。
 
在当前新版当linux实现中,由于listen socket积压队列满时,新的客户端连接并不会成为半打开连接,而是在connect调用时进行重传SYN段,如果达到了SYN_SENT状态的阈值后,tcp连接消失,应用层connect调用返回timeout异常!




推荐阅读