Jump to content
  • Advertisement
Sign in to follow this  
Jethro_T

Boost UDP Disconnect?

This topic is 2800 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!