考虑在 Windows 7 计算机上通过 localhost 上的 ncat 进行以下 TCP 通信:
航站楼 A
>ncat -4kvvl 127.0.0.1 5001
Ncat: Version 7.12 ( https://nmap.org/ncat )
Ncat: Listening on 127.0.0.1:5001
Ncat: Connection from 127.0.0.1.
Ncat: Connection from 127.0.0.1:52840.
BAM
NCAT DEBUG: Closing connection.
B 航站楼
>echo BAM | ncat -4vv 127.0.0.1 5001
Ncat: Version 7.12 ( https://nmap.org/ncat )
NCAT DEBUG: Using trusted CA certificates from ...
libnsock nsock_iod_new2(): nsock_iod_new (IOD #1)
libnsock nsock_connect_tcp(): TCP connection requested to 127.0.0.1:5001 (IOD #1) EID 8
libnsock nsock_trace_handler_callback(): Callback: CONNECT SUCCESS for EID 8 [127.0.0.1:5001]
Ncat: Connected to 127.0.0.1:5001.
libnsock nsock_iod_new2(): nsock_iod_new (IOD #2)
libnsock nsock_read(): Read request from IOD #1 [127.0.0.1:5001] (timeout: -1ms) EID 18
libnsock nsock_readbytes(): Read request for 0 bytes from IOD #2 [peer unspecified] EID 26
libnsock nsock_trace_handler_callback(): Callback: READ SUCCESS for EID 26 [peer unspecified] (6 bytes): BAM ..
libnsock nsock_write(): Write request for 6 bytes to IOD #1 EID 35 [127.0.0.1:5001]
libnsock nsock_trace_handler_callback(): Callback: WRITE SUCCESS for EID 35 [127.0.0.1:5001]
libnsock nsock_readbytes(): Read request for 0 bytes from IOD #2 [peer unspecified] EID 42
libnsock nsock_trace_handler_callback(): Callback: READ EOF for EID 42 [peer unspecified]
libnsock nsock_trace_handler_callback(): Callback: READ EOF for EID 18 [(null):-1]
close: Result too large
我第一次在终端 B 中运行 ncat 时,它会在 处挂起约 1 秒TCP connection requested to 127.0.0.1:5001
。套接字在 SYN_SENT 和 SYN_RCVD 状态下挂起(截屏)。
在后续运行中(终端 A 中的 ncat -k 继续监听),连接立即建立,这正是我所期望的,并且在其他 Windows 7 和 Linux 系统上也看到。
我觉得创建 TCP 连接的延迟会降低软件的速度(例如,连接到同一台机器上的内核的 IPython 控制台)。
这是怎么回事?
附加信息:
- Windows 防火墙已关闭。
- 在控制面板中停用所有网络适配器没有帮助。
- 例如,当我使用套接字时,我在 Python 程序中看到了这一点;我使用 ncat 作为最基本的测试。