Client/server autodetection on local network

Is there a standardized way to get a client and server program to be
able to find each other semi-automatically on a local network?

I’m the maintainer for an educational game (tuxmath -
http://tux4kids.alioth.debian.org) and am helping a Google SoC student
implement network play for the game using SDL_net. We now have the
game refactored into client and server programs, and everything works
OK. We are using TCP - the game uses negligible network bandwidth.

For the general public, I want the client program to be able to detect
if a game server is running on the local network. From some googling,
and primarily from Beej’s sockets tutorial, I am thinking that the
clients should send a UDP broadcast packet for a certain port, and the
server should listen on that report and reply with the server’s ip,
and the port number for actual game communication.

e.g.:

  • use port 4778 for detection and port 4779 for game itself
    (arbitrary numbers).

-client at, e.g., 192.168.1.100 broadcasts message to port 4778 saying
"looking for tuxmath server".

-server at, e.g., 192.168.1.105 sends packet back to 192.168.1.100
saying “connect your tcp socket to 192.168.1.105:4779”

Does this sound reasonable?

Thanks for any help or suggestions where else to look!

David Bruce

David Bruce wrote:

Is there a standardized way to get a client and server program to be
able to find each other semi-automatically on a local network?

I’m the maintainer for an educational game (tuxmath -
http://tux4kids.alioth.debian.org) and am helping a Google SoC student
implement network play for the game using SDL_net. We now have the
game refactored into client and server programs, and everything works
OK. We are using TCP - the game uses negligible network bandwidth.

For the general public, I want the client program to be able to detect
if a game server is running on the local network. From some googling,
and primarily from Beej’s sockets tutorial, I am thinking that the
clients should send a UDP broadcast packet for a certain port, and the
server should listen on that report and reply with the server’s ip,
and the port number for actual game communication.

e.g.:

  • use port 4778 for detection and port 4779 for game itself
    (arbitrary numbers).

-client at, e.g., 192.168.1.100 broadcasts message to port 4778 saying
"looking for tuxmath server".

-server at, e.g., 192.168.1.105 sends packet back to 192.168.1.100
saying “connect your tcp socket to 192.168.1.105:4779”

Does this sound reasonable?

Thanks for any help or suggestions where else to look!
That sounds okay, but I think that the server doesn’t have to send back
that the client should connect to a specified address. A answer like “I
am here” is enough. You get the server’s IP address from the UDP packet.
http://www.mindcontrol.org/~hplus/misc/lan-matchmaking.html

Regards,
Janosch Gr?f

That is exactly it. Its very easy to set up. BTW, UDP and TCP port
numbers are unrelated, you can use just a single port number.

Other than that, you don’t even need to include the IP address in the
reply packet, the client gets this information with the packet.On Thu, Jul 23, 2009 at 7:50 PM, David Bruce wrote:

Is there a standardized way to get a client and server program to be
able to find each other semi-automatically on a local network?

I’m the maintainer for an educational game (tuxmath -
http://tux4kids.alioth.debian.org) and am helping a Google SoC student
implement network play for the game using SDL_net. ?We now have the
game refactored into client and server programs, and everything works
OK. ?We are using TCP - the game uses negligible network bandwidth.

For the general public, I want the client program to be able to detect
if a game server is running on the local network. ?From some googling,
and primarily from Beej’s sockets tutorial, I am thinking that the
clients should send a UDP broadcast packet for a certain port, and the
server should listen on that report and reply with the server’s ip,
and the port number for actual game communication.

e.g.:
?- use port 4778 for detection and port 4779 for game itself
(arbitrary numbers).

-client at, e.g., 192.168.1.100 broadcasts message to port 4778 saying
"looking for tuxmath server".

-server at, e.g., 192.168.1.105 sends packet back to 192.168.1.100
saying “connect your tcp socket to 192.168.1.105:4779”

Does this sound reasonable?

Thanks for any help or suggestions where else to look!

David Bruce


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Does this sound reasonable?

It sounds reasonable, with the comments other have provided. You could
also use Avahi, if that’s an acceptable dependency for you, which
takes care of locating services on the local network for you. Since it
implements a more standard service discovery protocol, you could see
it working in a site where there are multiple subnets joined with a
Zeroconf-aware router, for example.On Thu, Jul 23, 2009 at 11:50 AM, David Bruce wrote:


That sounds okay, but I think that the server doesn’t have to send back
that the client should connect to a specified address. A answer like “I
am here” is enough. You get the server’s IP address from the UDP packet.
http://www.mindcontrol.org/~hplus/misc/lan-matchmaking.html

This is basically how every commercial game I’ve worked on does it.

Using something like Bonjour (Rendezvous, MDNS, whatever) is probably
more complex than you need for something like this.

–ryan.