Your opinion : Best way to find lan games

Started by
9 comments, last by md_lasalle 17 years, 7 months ago
Hey all! I want your opinions on finding lan games, i've search old posts but couldnt find what i'm looking for... I'll tell you how I do it, and i want to know if its possible to have a better/more robust approach. I use UDP broadcast... both the client and the server binds() a udp socket on port 11111... so evryone on lan can get packet sent to 255.255.255.255:11111 when a client wants the game list, it sends a broadcast asking "are you a server" and if servers are present, they answer : "yes I am, here are my game infos" so its pretty basic and working well. BUT if im behind a router that does not allow broadcast packet, it wont find my games at all. When i'm behind that router(that dont allow broadcast) i still can find games from games like Starcraft, Counter-Strike Source and Call of Duty 2 My question is : How they do it ?
Advertisement
LAN game finding and Internet matchmaking are very different functions.

Check the Forum FAQ for some links.
enum Bool { True, False, FileNotFound };
Well thank you hplus, but i've read the FAQ many times, and i'm not talking about Internet matchmaking as i have a master server up n running working perfectly...

The FAQ tells UDP broadcast is the most commun way to do it, thats what I did...but i dont think its the best way to do it. When I'm behing a router that disabled the broadcast, i cant find my game, and i still can find lan games from Starcraft, Cod2 and CSS... any clues on how they do it ?
Are you saying that you have two clients, with a router inbetween that filters broadcasts, and your broadcasts don't make it through, but a game like Warcraft III does, but it's all one big LAN (albeit with multiple LAN segments)?

There are other network protocols you can use (like IPX or the Windows protocols) which may not be filtered by the same router. For example, the Windows network/node browser uses a discovery protocol that might not be filtered. You could piggy-back on those services.

In general, though, I would suggest using IP broadcast for local LAN play, and Internet matchmaking for all cases where you want to go to another segment.
enum Bool { True, False, FileNotFound };
Yes I'm only talking about LAN matchmaking, sorry for the confusion...

I did some research, and for instance, someone has to find the broadcast adress on the current lan with subnet mask and stuff...the result was 5.255.255.255 to be able to braodcast

How do you calculate the right broadcast adress ? since we cannot assume 255.255.255.255 will be the one for anyway local network
If you get your current network address and current netmask from the device, then you just and the address with the mask -- that's what the "netmask" means.
enum Bool { True, False, FileNotFound };
Quote:Original post by hplus0603
...you just and the address with the mask...


do you mean ADD the adress with the mask ?

No - bitwise AND.

IP addresses and subnet masks are really 32-bit binary. Subnet masks are a number of 1s, starting at the left (another common notation refers to the number of 1s; 255.255.255.0 is /24 for a lot of router applications). For example, say you have a subnet mask of 255.255.255.0, and an IP address of 192.168.1.1.
In binary:
Netmask: 11111111 11111111 11111111 00000000
IP addr: 11000000 10101000 00000001 00000001

You can then do some binary arithmetic to discover various properties. The network address (for routing to the correct network) is the netmask (subnet mask) bitwise ANDed with the IP address:

Netmask: 11111111 11111111 11111111 00000000
IP addr: 11000000 10101000 00000001 00000001
AND : 11000000 10101000 00000001 00000000 (192.168.1.0)

Conversely, the HOST portion of the address (i.e. the number unique to your device on your network) is the portion of the address not used for network address (for a /24 as above, that leaves you with the last 8 bits). In this case the host address is 1. The BROADCAST address is what you get if all of the host (non-subnet) portion are 1s. Messages sent to the broadcast address are sent to everything on the subnet.

Netmask : 11111111 11111111 11111111 00000000
IP addr : 11000000 10101000 00000001 00000001

Host... : 00000000 00000000 00000000 00000001 (.1)
Broadcast:00000000 00000000 00000000 11111111 (.255)

Glueing the network and host portions back together, we find a broadcast address of 192.168.1.255:

Netmask : 11111111 11111111 11111111 00000000
IP addr : 11000000 10101000 00000001 00000001

Network : 11000000 10101000 00000001 00000000 (192.168.1.0)
PLUS
Broadcast:00000000 00000000 00000000 11111111
GIVES
Broadcast:11000000 10101000 00000001 11111111 (192.168.1.255)

I hope that helps.
Just to elaborate on the original question... if your router doesn't allow broadcasts within the same subnet (broadcasts aren't ever meant to go beyond the same subnet; blocking broadcasts within a subnet is pretty odd), then a broadcast UDP game finding technique isn't going to work. You would need a server receiving registrations of available games, and a system to retrieve available games from the server. On a LAN, within the same subnet, broadcasts should work fine so long as you determine the broadcast address correctly.
From md_lasalle, it sounds as if:

- he has a network with routers connecting different segments of the same subnet (oddness #1)
- a broadcast on 255.255.255.255 is filtered at the connecting router
- a broadcast on the specific subnet broadcast address (a.b.c.d | ~subnetmask) is not filtered at the connecting router

This sounds a little bit odd (because typically you'll have subnet == segment), but nothing totally illogical about it.

So, when I said "and" the subnet mask with the IP address, I really meant bitwise "and".

ipaddr = whatever;subnetmask = whatever;subnetaddr = ipaddr & subnetmask;subnetbroadcast = subnetaddr | ~subnetmask;


And, because masking subnetmask just sets the bits to zero that you will then set to one, you can skip that third step, and calculate subnetbroadcast from ipaddr and subnetmask, because you know that "(ipaddr & subnetmask) == (subnetaddr & subnetmask)" for any node (this is what it means to "be on a subnet").

subnetbroadcast = subnetaddr | ~subnetmask;


Now, all we need to know is if md_lasalle can confirm that this method works for his set-up.
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement