简体   繁体   English

在TCP客户端上接收数据包中的数据

[英]Receiving data in packets on TCP client

recv()调用会拦截数据包中的数据还是我可以获取带有时间戳的数据包?

On a datagram socket (like UDP), recv gets data in datagrams. 在数据报套接字(如UDP)上, recv以数据报形式获取数据。 TCP is a stream-mode socket, however, and recv gets a collection of bytes with no regard for packets. TCP是一种流模式套接字,但是recv会获得一个字节集合,而不考虑数据包。

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. 可以使用低级API来获取数据包,但是如果您希望查看send调用之间的界限,那么您很不幸……该信息不存在于数据包中。

Recv gets data from a socket that has been successfully received. Recv从已成功接收的套接字获取数据。 It does not tell you when that happened; 它不会告诉您什么时候发生; ie 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?) (或者我是否完全误解了您的问题?)

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. 尽管如上所述连接是TCP ...,但数据将采用流格式,而不像UDP那样是完整的数据包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM