Server broadcasting to find clients

Started by
1 comment, last by Dark Rain 18 years, 7 months ago
In the FAQ it says that finding your own IP is A Bad Thing(tm), so what would be the best manner to send a broadcast message to announce that there is a server available for clients to join? Obviously, if finding the local IP is a valid design concept, then it would be simple to determine the class of the address and replace the appropriate number of fields with 255. This is simple but not very elegant. Is there a better way? Thanks!
Advertisement
Most routers will filter UDP broadcasts. Thus, if you broadcast on the "Mars" address (255.255.255.255) and on your specific port, then the local machines that see your server will know where to reply back to, because the return address will be in their call to recvfrom(). Note that you need to do a special socket ioctl() before you're allowed to broadcast.

If you want to announce availability of the server wider than your local subnet, you have to use some sort of separate look-up, such as a known server/roster/introducer, or just plain DNS. Multicast is not really an alternative, because it's not well supported on the Internet in general (probably because it's a pretty poor match to today's Internet).
enum Bool { True, False, FileNotFound };
Well, if what you want to do is have a server with a non static ip then yes some kind of dns service with something like no-ip.org is appropriate.

But it sounds as if you're thinking of being able to see servers as in say Quake, Half-Life, Starcraft, Diablo etc. These games just use a known central server where all the player servers report their status and availability.

This topic is closed to new replies.

Advertisement