Sign in to follow this  

Get 'open Games' in LAN

This topic is 4715 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

This topic is 4715 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this