Jump to content
  • Advertisement
Sign in to follow this  
dantheman1337

How do I find other players?

This topic is 2703 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 know how to set up and use sockets. I know I have to use UDP sockets to broadcast. However, what I don't know, is how to find the other players using UDP. I wanna connect of LAN obviously. So can I be pointed to a tut on how do this? Can anyone shed some light?

Share this post


Link to post
Share on other sites
Advertisement
That is the point of broadcasting, you continuously send out a message blindly saying "here i am, come join me". Hopefully you will have another person in your network catching this message and connects to you via TCP and/or UDP.

Share this post


Link to post
Share on other sites
[color="#1c2837"][color="#000000"][font="arial, verdana, tahoma, sans-serif"][color="#1c2837"][color=#000000][font=arial, verdana, tahoma, sans-serif][size=2][font=arial, verdana, tahoma, sans-serif][size=2]
[color=#1C2837][size=2]you continuously send out a message blindly saying "here i am, come join me".[/quote][size=2][color=#1C2837][size=2]
[size=2][color=#1C2837][size=2]Actually, it's usually more efficient to have the clients broadcast when they are in "look-for" mode.[size=2][color=#1C2837][size=2]Typically, there will be a loop, where a client will select a random interval, on the order of 3-10 seconds. It will then broadcast a "discover" packet at that interval. Any server that sees that packet will send back a response with information about itself. Also, as soon as you start looking, the client will send a broadcast "discover" packet -- the slow re-sends are just to compensate for potentially lossy networks or late-coming servers.[size=2][color=#1C2837][size=2]Here, the approaches differ a little bit. Either, responses are sent as broadcast, so that all clients can see the servers, or responses are just sent back to the discoverer. Both options have benefits. A broadcast where everyone sees it will keep everyone up to date -- in fact, a client doesn't need to broadcast a "discover" packet if it has seen someone else send such a packet in the last N seconds. However, with more than one server on the subnet, or with a large subnet, the broadcast traffic may become inefficient.[size=2][color="#1c2837"][size=2]Unicasting a response back lets the network stay reasonably lightly loaded, but each new client that comes onto the network needs to broadcast a discover, and needs to keep sending discover packets every so often.[size=2][color="#1c2837"][size=2]
[size=2][color="#1c2837"][size=2]A fully broadcast-based system may look something like this:[size=2][color="#1c2837"][size=2]
[size=2][color="#1c2837"][size=2]client:[size=2][color="#1c2837"][size=2][source][size=2][color="#1c2837"][size=2]broadcast_discover[size=2][color="#1c2837"][size=2]interval = 3.0 + random(0.0 - 2.0) seconds[size=2][color="#1c2837"][size=2]while still looking:[size=2][color="#1c2837"][size=2] if more than interval since last discover seen[size=2][color="#1c2837"][size=2] broadcast_discover[size=2][color="#1c2837"][size=2] if server_data seen[size=2][color="#1c2837"][size=2] add or update update server_data in server list[size=2][color="#1c2837"][size=2] if haven't heard from a server on the list for 30 seconds[size=2][color="#1c2837"][size=2] drop server from list[size=2][color="#1c2837"][size=2][/source][size=2][color="#1c2837"][size=2]
[size=2][color="#1c2837"][size=2]server:
[color="#1c2837"][size=2][source][/font][size=2][color="#1c2837"][size=2]broadcast_server_data // takes care of any clients already listening[size=2][color="#1c2837"][size=2]while still accepting clients:[size=2][color="#1c2837"][size=2] if discover broadcast seen:[size=2][color="#1c2837"][size=2] set timer at random(0.0 - 0.5) seconds[size=2][color="#1c2837"][size=2] when timer expired:[size=2][color="#1c2837"][size=2] broadcast_server_data[size=2][color="#1c2837"][size=2][/source][size=2][color="#1c2837"][size=2]
[size=2][color="#1c2837"][size=2]This will generally get instant listings of servers on the network, without a client having to wait for a server to send its occasional ping, and still modulate network usage so it doesn't totally flood the network with broadcasts. The small random delay before servers respond is so that not all servers try to send their data at exactly the same time, which may cause dropped packets in networks with very small per-port buffers in the switches.
[color="#1c2837"][size=2]
[/font]
[color="#1c2837"][size=2]

[color="#1c2837"][size=2](Fifth edit: I give up -- it's apparently not possible to get a reasonable source block pasted into this forum. Which is kind-of annoying, given that it's about programming...)
[color="#1c2837"][size=2]
[/font]

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!