开发者

Can I get TCP/IP packet before it was sent?

There is a client and a server applications running on the same machine. They use asynchronous communication with TcpClient and TcpListener.

Server application do some data processing in a background worker thread. Every time each data portion is processed it tries to send it using TcpListener if any client is connected to it and had sent request to fetch processed data portion.

Immediatly after BeginWrite function call server sets client flag to avoid to send new data until client will send another request. As request arrives in TcpClientDataReadAsyncCallback() a flag is set to the client so that background worker can send data to that client

Here is the log of the server and client

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 is hh:mm:ss:ms

634538758557701309 numbers at the end of the lines are timestamps of the Request/Response objects to collate them in the logs

As you can see everything runs in due course until 191229 bytes object arrives before it was sent. Client does not send new request until response is recieved. I can not understand how that is possible.


It's entirely possible that it's an artifact of the logging. It could be some other thread interrupted your server thread after it sent the data but before it put the log down.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜