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

标签 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 字节的对象在发送之前到达。在收到响应之前,客户端不会发送新请求。我不明白这怎么可能。

最佳答案

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

关于c# - 我可以在发送之前获取 TCP/IP 数据包吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7719846/

相关文章:

c# - 第三方类的 TypeConverter 属性

.net - 除了必须总是自己编写之外,如何确保我们的函数在 F# 中使用缩写类型而不是基元?

c# - 在当前子网中找到免费 IP 地址的最简单方法?

java - 无法绑定(bind)到客户端中的广播地址 -- Java/Scala

c# - UWP Windows 应用商店应用程序上的 TLS 客户端证书身份验证

c# - 从 +/- 笛卡尔输入值计算屏幕坐标

c# - 将字符串转换为 unicode 表示

c# - C#中桌面应用程序的结构

c# - 套接字的远程地址为 0.0.0.0 且其状态为 Bound 意味着什么

c# - 降级 C# 6 代码