Receiving data in packets on TCP client

▼魔方 西西 提交于 2021-02-08 09:55:57

问题


Does recv() call intercepts data in packets or can i get data packets with timestamps?


回答1:


On a datagram socket (like UDP), recv gets data in datagrams. TCP is a stream-mode socket, however, and recv 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.




回答2:


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?)




回答3:


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.



来源:https://stackoverflow.com/questions/5048203/receiving-data-in-packets-on-tcp-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!