Quick question on select() when sending UDP packets

Started by
3 comments, last by stodge 17 years, 4 months ago
A quick UDP question when using select(). I have select() working for when bytes are received on a socket. I can happily pass them off to a Connection class, which processes the packets, parses the command and data etc.. However, when sending to a server on localhost, I'm losing lots of packets. Say I send 1000 unreliable packets from the client, the server only receives say 25%. The PC is an AMD 64 of some variety (can't remember) and there's nothing else of any interest going on at the time. CPU usage is low. When using UDP, do you: 1) use select() to tell you when a socket is ready for writing and then only send UDP packets when this occurs? 2) write packets as fast as you can to the socket, and let your reliable layer sort things out? 3) do something else I haven't considered? Thanks
---------------------http://www.stodge.net
Advertisement
Quote:Original post by stodge
A quick UDP question when using select(). I have select() working for when bytes are received on a socket. I can happily pass them off to a Connection class, which processes the packets, parses the command and data etc..

However, when sending to a server on localhost, I'm losing lots of packets. Say I send 1000 unreliable packets from the client, the server only receives say 25%. The PC is an AMD 64 of some variety (can't remember) and there's nothing else of any interest going on at the time. CPU usage is low.

When using UDP, do you:

1) use select() to tell you when a socket is ready for writing and then only send UDP packets when this occurs?
2) write packets as fast as you can to the socket, and let your reliable layer sort things out?
3) do something else I haven't considered?

Thanks


Udp is unreliable. If you send more packets that you can fit into the receive buffers, the system will drop the rest. You can increase the size of the receive buffer or send less packets. An alternative would be to process the packets faster, so the receive buffer never fills up.

Viktor

One of two things is happening:

1) You're sending too much, and thus overflowing some buffer somewhere. Given that UDP is unreliable, the packets get dropped.

2) You actually have a code bug, causing you to drop packets somehow.

To rule out 1), try inserting a ::Sleep(20) after each call to sendto(), to make sure the receiving end is being scheduled, and has time to deal with the packet.
enum Bool { True, False, FileNotFound };
make sure your not sending packets like every frame. Though I doubt the size would matter. How large are these packets. From my knowledge the receive buffer can hold a lot.
This is just a simple test so all packets are less than 20bytes. Some good things to think about- thanks.
---------------------http://www.stodge.net

This topic is closed to new replies.

Advertisement