Thread: multiple packets received between recvfrom calls

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    7

    multiple packets received between recvfrom calls

    hi, (using udp)
    if i receive multiple packets on a given socket before i make a call to recvfrom, will recvfrom return all the data it has received or just the contents of a single udp packet it received, in a queue like fashion? in the case it is not the latter, is there a way to make it as such, or must i use a large buffer and parse it on my own? thanks.

  2. #2
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    I *believe* the latter is the case, although I haven't used UDP myself. I read about it though [snip: Bad information; see posts below.]
    Last edited by Hunter2; 06-30-2006 at 08:05 AM.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    http://en.wikipedia.org/wiki/User_Datagram_Protocol
    Sounds like you're making way too many assumptions about the link, namely order and delivery (udp guarantees neither)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Which of us, or both?

    >>assumptions about the link, namely order and delivery
    As I understood it previously, while whole packets may arrive out-of-order, not arrive at all, or arrive several times, if a packet arrives at all then it will have arrived in its entirety. Is this incorrect, or was I just ambiguous?.. I remember puzzling over the wording in Winsock API for a long time.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  5. #5
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    My apologies. I found this on MSDN, in the docs for recvfrom():
    For message-oriented sockets, data is extracted from the first enqueued message, up to the size of the buffer specified. If the datagram or message is larger than the buffer specified, the buffer is filled with the first part of the datagram, and recvfrom generates the error WSAEMSGSIZE. For unreliable protocols (for example, UDP) the excess data is lost.
    But AFAIK, as long as you use a large enough buffer, you'll get the entire packet in one recv(), and not get the next packet. Of course, this *may* mean that packets will just be rejected until the first one is read, but I hope not.
    Last edited by Hunter2; 06-30-2006 at 08:08 AM.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 10:43 AM
  2. tuncated uint8_t
    By Coens in forum C Programming
    Replies: 14
    Last Post: 11-24-2008, 07:57 AM
  3. WSAGetLastError() is returning 0
    By 39ster in forum Networking/Device Communication
    Replies: 2
    Last Post: 07-16-2008, 06:57 AM
  4. Linker errors - Multiple Source files
    By nkhambal in forum C Programming
    Replies: 3
    Last Post: 04-24-2005, 02:41 AM
  5. socket question
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 07-19-2002, 01:54 PM