we're going to develop a game with internet multiplayer support. since it's an interactive game I know I have to use UDP to reduce connection latency, but I'm wondering what are the possible errors that may occur in a package delivered using UDP connection? everywhere I looked they say UDP provides "Best effort delivery", but开发者_StackOverflow no one does give a complete explanation what does it mean. after reading some article there are two questions that I still have:
- Is it possible to send a package and receive part of it at the other end of connection?
- if your answer to first quesiton is true what would happen to the next packages? should I wait for the rest of package or can I assume next package start with my next
recv
call?
for our game I think we will need to send 4 packages of around 20 byte each second.
The most common thing that can happen is: one side sends a message, the other receives nothing.
Is it possible to send a package and receive part of it at the other end of connection?
Not really, not even when the message is huge and it gets fragmented. Unlike in TCP
, in UDP
every message is independent. You either get it entirely or nothing at all.
So what you should do it just recvfrom
things in a loop and process them. Obviously you should make your application impervious to message loss such that a missing message doesn't crash it.
精彩评论