views:

41

answers:

2

The project I am working on is a client/server architecture. In a LAN environment, I want the client's to be able to automatically determine the server's address. I want to avoid having to manually configure each client with the ip address of the server. What is the best way to do this? Some alternatives I have thought about doing are:

  1. The server could listen for broadcast packets from the clients. The message from the client would be a request for the IP address of the server. The server would respond with its address.
  2. The machine running my project's server could also have a bind server running. The LAN's router could be configured to use it as one of its DNS servers.
  3. I think I saw that there is a bind library. Does that mean I can build the bind service into my server so that bind doesn't have to be installed on the server?

Any other ideas? What have you done in the past? What are the pros/cons of these approaches and others that might be suggested?

Thanks for your help!

+1  A: 

I like number one, that seems shortest and simplest to me. Might get tricky if the "LAN" actually involves switches that you can't broadcast through. Multicasting should help, then.

You can also use DNS, as in Zeroconf. See Bonjour for information about an implementation.

unwind
Bonjour is free for clients. Is it free for servers as well?
zooropa
+1  A: 

You can use WCF 4.0's new Discovery feature. Two things are possible:

  1. The server can announce to the network that he has gone up or down, and clients can connect to it or look elsewhere, respectively.
  2. The client broadcast an inquiry for a service and all matching services on the network will reply. The client can then pick the service he wishes to use.

You can use either or both, and it's all handled by WCF, so there's little work to actually use it. You can even set up WCF proxies if you have a restrictive network topology (such as NAT or other routing issues). The proxies can cross/convert protocols and even have custom load-balancing or other routing logic.

http://msdn.microsoft.com/en-us/library/dd456782.aspx

Allon Guralnek
I think this would be a good solution if all clients and the server are Windows based. Would it work if the server is communicating with an iPad?
zooropa
Well most of the stuff is WS-Discovery, a web standard that is platform independent. If you use an iPhoneOS client that supports that standard, then it will work. See http://en.wikipedia.org/wiki/WS-Discovery
Allon Guralnek