3

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 no one does give a complete explanation what does it mean. after reading some article there are two questions that I still have:

  1. Is it possible to send a package and receive part of it at the other end of connection?
  2. 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.

Ali1S232
  • 3,373
  • 2
  • 27
  • 46
  • If possible, try to combine those four packages into one. The overhead will be smaller. – DarkDust Sep 24 '11 at 15:26
  • I presume "packet" is meant instead of "package" or a message than can be fragmented over many packets? – Steve-o Sep 24 '11 at 15:27
  • Consider you have guarantees on minimum packet size which allows you to send more information per update: http://stackoverflow.com/q/1098897/175849 – Steve-o Sep 24 '11 at 15:32

1 Answers1

2

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.

cnicutar
  • 178,505
  • 25
  • 365
  • 392
  • On Linux with [UDPlite](http://en.wikipedia.org/wiki/UDP_Lite) you can receive partial packets, useful for streaming video, useless for pretty much everything else. – Steve-o Sep 24 '11 at 15:28