使用 .NET 进行 TCP 编程
我在套接字编程工作中遇到问题。我编写了一个通过套接字/网络流发送命令的 TCP 客户端。我正在使用 Wireshark 来查看通过电线的原始数据。 每次我发送“命令”(意味着我 Flush() 网络流)时,Wireshark 应用程序都会告诉我 TCP 标头中的校验和不正确(说“它应该是 0x2440,但实际上是 0x0000)。我确实收到了 ACK 。 我不明白为什么在应用程序层我必须关心 TCP 标头。那是不对的。 有人知道为什么我会收到这个“错误”吗?是否有我不知道的设置? 我正在使用带有 Tcp 的 .NET 2.0 套接字。 谢谢。
I'm having an issue with a socket programming job. I wrote a TCP client that sends commands via sockets/networkstream. I'm using Wireshark to look at the raw data that goes through the wires.
Everytime I send a "command" (meaning I Flush() the networkstream), the Wireshark application tells me that the checksum in the TCP Header is incorrect (says "it should be 0x2440, but is 0x0000). I do get an ACK back.
I don't understand why at the application layer I would have to care about the TCP header. That can't be right.
Would anyone know why I am getting this "error". Is there a setting I'm not aware of?
I'm using .NET 2.0 sockets with Tcp.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否正在查看发送数据的计算机上的 Wireshark 转储?如果是这样,可能只是在 Wireshark 看到的堆栈点处尚未计算校验和。现在许多网卡都有 TCP 校验和卸载,其中校验和由硬件完成,因此校验和字段在输出时将为零(Wireshark 在数据包发送到硬件之前获取数据包)。既然你收到了 ACK,那么接收端显然对此很满意。另外,如果您正在与本地主机对话,您的堆栈可能根本不会担心校验和(对于主机与自身对话来说,它们并不是绝对必要的)。
Are you looking at a Wireshark dump from the machine that is sending the data? If so, it may just be that the checksum hasn't been calculated at the point in the stack where Wireshark is seeing it. Many network cards these days have TCP Checksum Offload, where the checksum is done by hardware, and so the checksum field will be zero on the way out (Wireshark gets the packet just before it is sent to the hardware). Since you're getting ACKs, the receiving end is clearly cool with it. Also, if you're talking to localhost, your stack may not be bothering with checksums at all (they aren't strictly necessary for a host talking to itself).