Sign in to follow this  

Boost UDP Disconnect?

This topic is 2645 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

I'm trying to write a simple client and server using boost ASIO UDP. How can I handle the sending of packets when certain packets need to be sent to every client and others must only be sent to a single client. Do I use connect() to send to a single client? How can I disconnect in order to broadcast packets after doing this?

Thanks.

Share this post


Link to post
Share on other sites
UDP is connectionless. All you need is an endpoint and you can use send_to or async_send_to. When you get packets from clients you want to keep track of their endpoints by putting them into a data structure like an array. Naively if you wanted to send to everyone you'd iterate all the clients and call send_to or async_send_to with your data. If you want to send to a single client you just send to that client's endpoint. (A more sane way is to have outgoing queues of messages or something so you don't spam tons of small packets).

Follow the tutorials in the documentation

Since UDP is connectionless you have to find a way to keep track of which clients are still alive. This can be done with a simple keep alive packet sent by the client or you can have the server do pings and track responses from the clients. (That is you expect a pong back from the client. If you don't get one you remove the client from the list of clients or something).

Share this post


Link to post
Share on other sites

This topic is 2645 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