views:

58

answers:

5

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?

A: 

Check out http://en.wikipedia.org/wiki/Broadcast_address

Will A
+1  A: 

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

DrDeth
A: 

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/

rakuo15
A: 

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.

Eric
Blindly changing the last byte will not always work. It depends on the actual subnet mask being used on the network. The correct way to generate a broadcast address is to take the local computer's IP, `AND' it with the subnet mask, then 'OR' it with the inverse of the subnet mask. Alternatively, just use the global broadcast address 255.255.255.255, but not all firewalls/routers will allow that to pass through.
Remy Lebeau - TeamB
A: 

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.

young