UDP packets

Giganews Newsgroups
Subject: UDP packets
Posted by:  Malcolm Smith (nospam@nospam.com)
Date: Fri, 21 Sep 2007

I have code that sends UDP data based on a max size, pushing via multiple
calls to SendTo like so:

while( ASizeLeft > 0 )
  {
  AByteCount = std::min<int>( FMaxDatagramSize, ASizeLeft );

  const void *pcStart = pStart;
  void *pBuffStart = const_cast<void*>( pcStart );

  if( 0 == FUDPPort )
    FSocket->Send( pBuffStart, AByteCount, 0 );
  else
    FSocket->SendTo( FUDPIP, FUDPPort, pBuffStart, AByteCount );

  pStart += AByteCount;
  ASizeLeft -= AByteCount;
  }

As such, if I was to send a huge amount of data that required several calls
to SendTo() is it true to say there is a potential for the data to arrive at
the client in the wrong order (I'm sending data over the internet).  ie, 4
calls 1, 2, 3, 4 may be received as 2, 4, 3, 1 ?

I'm having difficulty with some client code and I suspect the above is
occurring.

If this is true, can I also assume that any data sent (in a single call to
SendTo) will either be received in full (possibly corrupt), or not at all.

--
Malcolm Smith
MJ Freelancing
http://www.mjfreelancing.com

Associate Editor
C++Builder Developers Journal
http://www.bcbjournal.com

Replies