我能在TCP/IP数据包发送之前得到它吗?

本文关键字:TCP 数据包 IP | 更新日期: 2023-09-27 18:11:05

在同一台机器上运行一个客户机和一个服务器应用程序。它们与TcpClient和tcpplistener使用异步通信。

服务器应用程序在后台工作线程中执行一些数据处理。每次处理每个数据部分时,如果有任何客户端连接到它并已发送请求以获取已处理的数据部分,则尝试使用TcpListener发送它。

在BeginWrite函数调用后,服务器立即设置客户端标志以避免发送新数据,直到客户端发送另一个请求。当请求到达TcpClientDataReadAsyncCallback()时,一个标志被设置为客户端,以便后台工作器可以向该客户端发送数据

这是服务器和客户端的日志

server
00.37.35.772 127.0.0.1:6012 recv 257 bytes of client Request 634538758557701309
00.37.35.860 127.0.0.1:6012 sent 175652 bytes to client
00.37.35.892 127.0.0.1:6012 recv 257 bytes of client Request 634538758558675330
00.37.35.952 127.0.0.1:6012 sent 188927 bytes to client
00.37.35.983 127.0.0.1:6012 recv 257 bytes of client Request 634538758559585382
00.37.36.052 127.0.0.1:6012 sent 174790 bytes to client
00.37.36.083 127.0.0.1:6012 recv 257 bytes of client Request 634538758560595440
00.37.36.153 127.0.0.1:6012 sent 188491 bytes to client
00.37.36.187 127.0.0.1:6012 recv 257 bytes of client Request 634538758561605498
00.37.36.249 127.0.0.1:6012 sent 178723 bytes to client
00.37.36.280 127.0.0.1:6012 recv 257 bytes of client Request 634538758562491540
00.37.36.373 127.0.0.1:6012 recv 257 bytes of client Request 634538758563739542
00.37.36.436 127.0.0.1:6012 sent 191229 bytes to client
client
00.37.35.864 127.0.0.1:6012 recv 175652 bytes of server Response 634538758558455318
00.37.35.867 127.0.0.1:6012 sent 257 bytes Request to server 634538758558675330
00.37.35.957 127.0.0.1:6012 recv 188927 bytes of server Response 634538758559455375
00.37.35.959 127.0.0.1:6012 sent 257 bytes Request to server 634538758559585382
00.37.36.056 127.0.0.1:6012 recv 174790 bytes of server Response 634538758560455432
00.37.36.059 127.0.0.1:6012 sent 257 bytes Request to server 634538758560595440
00.37.36.158 127.0.0.1:6012 recv 188491 bytes of server Response 634538758561465490
00.37.36.160 127.0.0.1:6012 sent 257 bytes Request to server 634538758561605498
00.37.36.249 127.0.0.1:6012 recv 178723 bytes of server Response 634538758562491540
00.37.36.249 127.0.0.1:6012 sent 257 bytes Request to server 634538758562491540
00.37.36.373 127.0.0.1:6012 recv 191229 bytes of server Response 634538758563583542
00.37.36.373 127.0.0.1:6012 sent 257 bytes Request to server 634538758563739542
00.37.41.412 client timed out RX operation

00.37.35.772是hh:mm:ss:ms

634538758557701309行尾的数字是请求/响应对象的时间戳,以便在日志中整理它们

正如您所看到的,一切都在适当的时候运行,直到191229字节的对象在发送之前到达。客户端在收到响应之前不发送新的请求。我不明白这怎么可能。

我能在TCP/IP数据包发送之前得到它吗?

这完全有可能是日志记录的产物。这可能是其他线程在发送数据后,但在记录日志之前中断了服务器线程。