Can recvfrom() read more then a packet?

Started by
3 comments, last by frob 12 years, 10 months ago
Hi

I am wondering if recvfrom() given a lengthy buffer to read to would read more then a packet in non-blocking mode. Or will this read one packet at the time? Let's say I have a buffer[1400] passed to recvfrom() and the payload of the first packet in queue is 60 bytes and the next packet has 80 bytes. Will both packets be read in the same call?

It would simplyfy my code alot if only one packet was read at a time (packets may vary in size).

I am also concerned that sendto() may send less then the requested load and that if I should resend the rest of the information then that would show up as another packet on the reciever and be read as suggested above. If so I will have to have a spaciel header consisting of maybe 64 "1"'s (bit stuffing to prevent information to appear as a header), then a ID and a packet number in order to append it to the previous packet. (a third packet my come between the two).

I do not wish to go into serialization atm, I wish to just cast my structs into char, should work if I only work in Windows right?

Thanks
Advertisement
Have you read the documentation for recvfrom()?
When using UDP, only one packet is received per call to recv or recvfrom. Each call to send or sendo will create a single packet per call to send to the destination. But beware, do not try to send a packet that is too large, i.e. don't send a 5 MB packet. How do you figure out how big is too big? There is something called Maximum Transmission Unit, which is a term meaning the biggest size packet that will not be fragmented by the network that can be sent. Currently, you are guaranteed that a packet the size of 576 bytes will not be broken up when sending. But, most likely, a size of around 1440 bytes is safe. I am trying not to go into detail because there is alot of background information.
You should read up, http://www.garykessler.net/library/tcpip.html
Wisdom is knowing when to shut up, so try it.
--Game Development http://nolimitsdesigns.com: Reliable UDP library, Threading library, Math Library, UI Library. Take a look, its all free.

Have you read the documentation for recvfrom()?


"Well, here's the second of the one-two punch: you might have read past the end of one packet and onto the next in a single recv() call. "

I read this here: http://beej.us/guide/bgnet/output/html/singlepage/bgnet.html

So I got confused

[quote name='rip-off' timestamp='1307115731' post='4819093']
Have you read the documentation for recvfrom()?


"Well, here's the second of the one-two punch: you might have read past the end of one packet and onto the next in a single recv() call. "

I read this here: http://beej.us/guide...page/bgnet.html

So I got confused
[/quote]


recv() and recvfrom() are different functions with different properties.

recv() is stream-based and can extract more or less than a single game-transmitted packet.

recvfrom() has various options that can enable it to read exactly one packet, optionally discard data, or operate as a stream-based read.

This topic is closed to new replies.

Advertisement