Search code examples
javasocketsnetwork-programmingsocketserver

Seeing multiple servers on a network


I am busy with a project where I'm creating a basic client/server chat application which allows a user to create a server on their local network on a port of their choice and then have multiple clients connect to that server by specifying the IP and port number of the server(So far so good).

I would like to how I can have clients see all the possible servers they can connect to on their local network when there are multiple servers running on their local network over different ports and then allowing them to connect to one. I am using basic Java socket programming for this project.


Solution

  • You could have

    • use a UDP based protocol where each server publishes it's IP:port every second.
    • you could have a service where each server registers. You could chat with that to get the list of all services.

    The nice approach of the later option is you can use one of your chat services for server discovery. When you want to get the list, you send a message to a channel on that server which all the servers are listening to and they respond with a chat message.