Sign in to follow this  

Quick question on select() when sending UDP packets

This topic is 4033 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

This topic is 4033 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this