Advertisement

Automatically Detecting LAN Games

Started by April 26, 2006 05:06 PM
3 comments, last by hplus0603 18 years, 9 months ago
Hey guys, Some friends and I are writing an RTS-ish game for Tablet PCs for a class that we are taking. Our game uses a client/server architecture and supports n-way multiplayer (where n is some huge number). Currently, to connect to a game, the clients must all type in the IP address of the server. We think this is pretty lame, and would like to automatically detect open games on a LAN (similar to how Warcraft III does when searching for LAN games). We are using straight up TCP in C# and since these are Tablet PCs, we are talking about wireless connections (I'm not sure if that matters). The optimal solution would allow Tablet PCs with wireless connections to automatically find games hosted on PCs with physical ethernet connections (and vice versa). I think this means we can't just search the local subnet. I'm thinking we need to tell the servers to post about their games at a known URL, with the info to connect to them. Is there a better way?

Shedletsky's Bits: A Blog | ROBLOX | Twitter
Time held me green and dying
Though I sang in my chains like the sea...

So are you saying you can't use broadcast to find games? Being able to use broadcast is pretty much my definition of a LAN game.

Do wireless routers have decent support for multicast? That might be another option.

-Mike
Advertisement
Try this.

Apparently it should work on tablet pc.
Correct me if I'm wrong but cant you send a UDP packet to 255.255.255.255 and it will broadcast it across the whole network. Just have a separate port open on your server which listens for this broadcast and go from there.
Delphi C++ OpenGL Development: www.nitrogen.za.org
1) Open a known port on the server.
2) Listen for UDP broadcasts on this port.
3) When you get a broadcast containing the right "key" data, reply back with your game information. (The IP address will already be part of the IP headers)

When a client starts up, it opens up a UDP port, and broadcasts the "key" data on this port, which the server/servers will reply to with game information.

Your clients might want to send the broadcast once every 5 seconds or so, to catch new servers coming online, or packets you might have missed the last time around.

It's a good idea to use some specific "key" at the head of your broadcast packets, to be more resilient to collisions with other protocols on the same port. Start each packet with "hplus-FTW" for example -- there's nothing else that uses that ;-)
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement