【发布时间】:2011-12-04 21:53:42
【问题描述】:
有一个客户端和一个服务器应用程序在同一台机器上运行。 它们使用与 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 字节对象在发送之前到达。客户端在收到响应之前不会发送新请求。我不明白这怎么可能。
【问题讨论】:
标签: c# .net networking tcpclient tcplistener