views:

121

answers:

2

I'm writing a client-server application where client should be able to automatically detect server presence in the network so that user would not have to mess with manual configuration.

I think that server should broadcast its presence somehow. What is the best way to do it?

Server is to be run on either Windows / Linux or OS X, so the solution should be cross-platform. Client and server are written in C++.

+4  A: 

You should look into ZeroConf as a generic way of broadcasting this information. It's also known as Bonjour (formerly Rendezvous) on Apple systems, but it's not an Apple-specific thing - plenty of other devices (both embedded and OSs) broadcast/use it.

There are plenty of libraries that can deal with ZeroConf in plenty of languages - finding one is a matter of Googling it. Bear in mind that ZeroConf itself is the advertising/discovery part of the process and identifies a machine and a socket - but you can then do whatever you want over the socket(s) that you identify.

For example, Apache mod_zeroconf allows you to broadcast Apache sites. Your solution will be dependent on what licensing and usage rights you're dependent on.

AlBlue
+1  A: 

If you want to do it yourself you can use multicasting. Some (braindead) ways to do that are: 1) have the server periodically advertise it's presence to the subscribed clients, followed by unicast transmissions between the client & the server; 2) have the client signal (a number of times) it's presence to the subscribed server(s), again followed by unicast transmissions between server & client. One more thing that needs to be considered it that the multicast will be all UDP and the unicast can be either TCP or UDP.

Eugen Constantin Dinca