Get 'open Games' in LAN

Started by
3 comments, last by markr 19 years, 2 months ago
In my networked game, i try to figure out, which pc in the neighborhood has an open game to offer. via WNetEnumResource i get all connected pc's. Then i try to connect to every pc in the retrieved list on the special game-port. if it succeds, i send a "please send me your open games" command. after connecting to all pcs, i just have to wait, until all open games send a "here is my open game" to me. the problem with this approach is the connection to all other pc. it takes to long. i then thought about a server, who collects all games that connect to the port, the problem seems to be the same: i've to try every ip in the LAN to find the server, so nothing is gained. Is there another approach to get open games? how do other games solve this problem? Regards, Philipp
Advertisement
Answer: UDP Broadcasting

Google for the technical specifics and implementation. Basically you construct a packet to ask any servers that may be running to reply with their game details. This way you don't have to wait until a timeout if a game server is not running on a particular node.
I've never used broadcasting myself but do you not just send to IP 255.255.255.255? It will send to all clients on the network. You just have to listen on a specific port for a reply.
You must turn on the socket option to enable broadcasting, at least on Windows.

int one = 1;int r = ::setsockopt( fd_, SOL_SOCKET, SO_BROADCAST, (char const *)&one, sizeof(one) );

Then send to 255.255.255.255, and some specific port. You probably should put a "magic cookie" as the first DWORD of your packet, if you happen to collide with someone else on the same port on the network, so you can validate the likelihood that the data really is yours.
enum Bool { True, False, FileNotFound };
Quote:Original post by hplus0603
You must turn on the socket option to enable broadcasting, at least on Windows.


As far as I'm aware, so should you on any OS that supports BSD sockets.

Mark

This topic is closed to new replies.

Advertisement