🎉 Celebrating 25 Years of GameDev.net! 🎉
Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!
Getting all the recvfrom() has to offer
In general thus far I''ve just assigned a 4k buffer to recvfrom() so I can read in the data recieved. I''m sure I''ll run in to trouble with this eventially though.
Is there a better way? Perhaps finding out the size of the data sockets is holding before I recvfrom() to ensure I have big enough buffer.
thanks
gimp
Certainly...
Check out ioctlsocket() with the FIONREAD flag. It will tell you how much data is pending.
// CHRIS
Check out ioctlsocket() with the FIONREAD flag. It will tell you how much data is pending.
// CHRIS
Another way is to just call recv() with, say, a 4K buffer. If the recv() reads a full 4K, then repeat until the function returns a ''bytes read'' value less than 4K..
Keep in mind that if you call recv() the first time and get 0 (zero) bytes read, it''s a flag that the other side has closed the connection.
// CHRIS
Keep in mind that if you call recv() the first time and get 0 (zero) bytes read, it''s a flag that the other side has closed the connection.
// CHRIS
If you are using UDP, repeated recv''s won''t work. Each successive recv gets the next packet; if your buffer is too small, the rest is lost.
However, packets cannot be more than 64Kbytes, actually a little less because of the packet header. So you could just have
and be OK.
Of course, I wouldn''t be comfortable sending larger than 8K packets over the internet, well, not even 2K really.
However, packets cannot be more than 64Kbytes, actually a little less because of the packet header. So you could just have
static char buffer[0x10000];
and be OK.
Of course, I wouldn''t be comfortable sending larger than 8K packets over the internet, well, not even 2K really.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement