我可以在发送之前获取TCP / IP数据包吗?

时间:2011-10-10 23:33:29

标签: c# .net networking tcpclient tcplistener

在同一台计算机上运行客户端和服务器应用程序。 他们使用与TcpClient和TcpListener的异步通信。

服务器应用程序在后台工作线程中执行一些数据处理。每次处理每个数据部分时,如果有任何客户端连接到它并发送了获取已处理数据部分的请求,它会尝试使用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字节对象在发送之前到达。在收到响应之前,客户端不会发送新请求。我无法理解这是怎么可能的。

1 个答案:

答案 0 :(得分:4)

完全有可能它是日志记录的工件。可能是某些其他线程在发送数据之后但在放下日志之前中断了服务器线程。