0

I have a spreadsheet application in Java, and one of the features it provides (which I developed) is sheet sharing. Basically, anyone can be a client or a server because the app has both server and client code. The user who is the server creates the share, specifies the IP, and then the share is created and active (best case scenario) with the server listening for clients on its IP and selected port.

At the moment, the client needs to enter the IP and port of the server that's listening in order to connect. The server then creates a new socket for that client and communicates with in on a separate thread, while the server continues listening on another (traditional TCP behavior). This is all working fine.

What I need to develop is auto-discovery, e.g. a client does not need to type in an IP or port, they simply select 'Join a share...' from the menu and then it starts looking for servers. When one is found, it should send its list of active shares on that IP. The user then selects which share to join from the list, and is connected.

However, I have doubts on how to tackle this issue. Should I use broadcast to poll servers, like DHCP does? Or is there an easier way?

What I'd like to implement is:

Client -> polls local network -> finds a server -> server sends active share list to client -> client selects share to join -> connected!

swiftcode
  • 3,039
  • 9
  • 39
  • 64
  • [Possible duplicate](http://stackoverflow.com/questions/3258959/network-discovery-in-java-using-multicasting) – npe Jun 12 '12 at 14:31

1 Answers1

0

Technically, what you're looking for is active servers that are running your spreadsheet application.

One possibility would be for your server code to send out an "alive" message to the network every so often (say every 15 seconds). Your client code would listen for these "alive" messages, and produce a meaningful list of spreadsheet servers.

Another possibility would to to use the same database engine that you're using to store the spreadsheets to store the IP and port of the connected server code. The client code would just read the database table to get the connections.

Gilbert Le Blanc
  • 50,182
  • 6
  • 67
  • 111