Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 192.168.0.1, then 192.168.0.2, etc? Is there a better way?

like image 452
Lost Developer Avatar asked Jul 08 '10 23:07

Lost Developer


3 Answers

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

like image 57
DrDeth Avatar answered Sep 21 '22 15:09

DrDeth


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/

like image 30
rakuo15 Avatar answered Sep 23 '22 15:09

rakuo15


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.

like image 23
young Avatar answered Sep 20 '22 15:09

young