C socket: does send wait for recv to end?

后端 未结 5 798
生来不讨喜
生来不讨喜 2020-12-15 11:36

I use blocking C sockets on Windows. I use them to send updates of a data from the server to the client and vice versa. I send updates at a high frequency (every 100ms). Doe

5条回答
  •  余生分开走
    2020-12-15 11:59

    If you're sending by TCP, you get guaranteed delivery1 and the other end will receive the data in the order sent. That might, however, be coalesced together so what you sent as 10 separate updates could be received as a single large packet (or vice versa -- a single update could be broken up across an arbitrary number of packets). This means, among other things, that any ACK of any data implicitly acknowledges receipt of all previous data.

    If you're using UDP, none of that is true -- data can arrive out of order, or be dropped and never delivered at all. If you care about all the data being received, you just about need to build some sort of acknowledgement system of your own on top of UDP itself.

    1 Of course, there's a limit on the guarantee -- if a network cable gets cut (or whatever) packets won't be delivered, but you'll at least get an error message telling you that the connection was lost.

提交回复
热议问题