Java: How to make clients discover the server on the network?

During my years at the university, I had a personal project for creating a simple chat program in Java using TCP sockets. The project was intended for educational purposes only.

One thing that I was not very happy with was that the client had to know the IP address of the server in order to connect to it. So I thought it would be nice if clients could find out if there are any chat servers on the network.

How can I implement such a mechanism? If you could point me in the right direction, I would be grateful. :-)

I think the server will have to do some kind of translation, but I'm not sure how to do this.

PS: I know that there may be other / better ways to do this, but at the moment I am particularly interested in how to get the client to detect servers on the network.

And by server, I mean the server side of the chat application, not the Tomcat server.

+4
source share
3 answers

There are many ways to do this, but I recommend you check out JGroups . This may be somewhat redundant for a chat application, but its use of multicast offers interesting features, such as a serverless architecture.

+3
source

Take a look at ZeroConf, which provides mechanisms for declaring and discovering services. Apple makes extensive use of this name called Bonjour.

The jmdns project is a Java implementation that works quite well. http://jmdns.sourceforge.net/

+2
source

You can try using multicast if it is enabled on your network.

+2
source

All Articles