Scan LAN game servers using winsock

I am trying to figure out how to use winsockets to be able to turn my game into a game played on the local network. I read some winsockets documentation, but I can’t understand how the client can get all the games created on the local network.

Should I try to "connect" to each IP network, for example, try to connect to 192.168.0.1, then 192.168.0.2, etc.? Is there a better way?

+6
networking lan winsock
source share
4 answers

You would use broadcasting to advertise your servers on the local network. Clients can then listen to these broadcasts to find servers.

See here for more information: http://tangentsoft.net/wskfaq/intermediate.html#broadcast

+3
source share

Typically, these game servers use the local UDP broadcast, which all clients receive and can process as long as they listen to it.

Here is an example client and server code that I found that might interest you: http://visual-c.itags.org/visual-c-c++/29424/

+2
source share

I think there are two possible ways to do this.

  • Make a "lobby" that clients and servers connect to so they can find each other through it.

  • Servers transmit UDP packets. Clients listen and update the list of servers.

If you need a quick and easy way, the second option will be great, but remember that most UDP packets will be wasted because they are used only once for each client.

The first option is a more general and extended solution to this problem. However, development and implementation may take longer.

+2
source share

First of all, I suggest you get wirehark for any network development. It will show you which package passes through the wire. This will allow you to see how other games do it, as there are many ways to do this.

Using UDP broadcasting is one way to do this. Just change the last target IP address to 255 and you should be fine.

0
source share

All Articles