TCP客户端接收数据包
recv() 调用是否会拦截数据包中的数据,或者我可以获得带有时间戳的数据包吗?
Does recv() call intercepts data in packets or can i get data packets with timestamps?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在数据报套接字(如 UDP)上,
recv
获取数据报中的数据。然而,TCP 是流模式套接字,而recv
获取字节集合而不考虑数据包。使用低级 API 来获取数据包是可能的,但如果您希望看到
send
调用之间的边界,那么您就不走运了……该信息不存在于数据包中。On a datagram socket (like UDP),
recv
gets data in datagrams. TCP is a stream-mode socket, however, andrecv
gets a collection of bytes with no regard for packets.It's possible, using low-level APIs, to get the packets, but if you were hoping to see boundaries between
send
calls you are out of luck... that information is not present in the packets.Recv 从已成功接收的套接字获取数据。它不会告诉你这件事是什么时候发生的;即没有时间戳。
您能否详细说明您想要解决的问题(“为什么需要这个?”)而不是您尝试的解决方案? (或者我完全误解了你的问题?)
Recv gets data from a socket that has been successfully received. It does not tell you when that happened; i.e. no timestamp.
Would you elaborate on what problem you're trying to solve ("why do you need this?") instead of your attempted solution? (Or have I completely misunderstood your question?)
如果您自己的代码正在将数据发送到您正在接收数据的远程计算机...那么您可以制定自己的应用程序级数据格式...例如在发送时间戳(某些指定的字节数)之后发送数据。
该信息可以在接收端提取。尽管如上所述连接是 TCP ...数据将采用流格式,而不是像 UDP 那样作为完整的数据包。
If your own code is sending data to the remote machine where you are receiving data...then you can make you r own application level data format...such as sending the data after sending timestamp (some specified number of bytes).
This information can be extracted at the receiving end. Although as mentioned connection is TCP ...the data would be in stream format not as a complete packet as in case of UDP.