Tutorial :Scanning LAN game servers using winsock


I'm trying to figure out how to use winsockets to be able to turn my game into a LAN-playable game. I've read some winsockets documentation but I can't figure out how a client can get all the games that were created on LAN.

Does it have to try to 'connect' to each IP on LAN, like trying to connect to, then, etc? Is there a better way?


You would use broadcasting to advertise your servers on the LAN. Clients can then listen for these broadcasts to 'find' servers.

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


Typically these game servers use the local UDP broadcast, which is something that all clients receive and can process so long as they are listening to it.

Here is some sample client and server code I found that may be of interest to you: http://visual-c.itags.org/visual-c-c++/29424/


I think there are two possible ways to do this.

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

  2. Servers broadcast UDP packets. Clients listen and update a list of servers.

If you need a quick and easy way, the 2nd option would be great but remeber most of UDP packets will be wasted as they are used only once for each client.

The 1st option is more general and extensile solution to this problem. However, it might need more time to design and implement.


First off, I suggest that you get wireshark for any networking development. It will show you what packet goes through the wire. It will allow you to see how other games do it since there are many ways of doing this.

Using the UDP broadcast is one way of doing it. Simply change the target ip's last byte to 255 and you should be ok.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »