• Post Reply Bookmark Topic Watch Topic
  • New Topic

Finding All Computers and check if its Running the Java Server

 
vyshak vijayan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a Java Server running on the computer.I have an Client which sends a File to this Server.In normal use cases i dont know which computers are running the server program.I plan to get all the machines on the Network like this



But how can i detect which Machines are running the Server.The below is the server program


Please Advise.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35709
408
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While you could check if a port is open, this is likely to be the case for multiple machines.

This seems like an unusual way for a client to find the user. A better way is for the client to look for a certain alias or machine name or ip address...
 
Ron McLeod
Saloon Keeper
Posts: 1263
131
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the clients and servers are in the same subnet/broadcast-domain, then you could have the server(s) periodically send messages to the network's broadcast IP address. The clietns could then listen for the messages to discover the running server(s).

In addition to just announcing the server's presence, the message could also contain other information useful to the client such as the port number where the server is listening for submissions, maximum submission size, current state, etc.
 
vyshak vijayan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:While you could check if a port is open, this is likely to be the case for multiple machines.

This seems like an unusual way for a client to find the user. A better way is for the client to look for a certain alias or machine name or ip address...


Its not possible since i cannot ask the user to enter an IP.How do you suggest to implement this?
 
vyshak vijayan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ron McLeod wrote:If the clients and servers are in the same subnet/broadcast-domain, then you could have the server(s) periodically send messages to the network's broadcast IP address. The clietns could then listen for the messages to discover the running server(s).

In addition to just announcing the server's presence, the message could also contain other information useful to the client such as the port number where the server is listening for submissions, maximum submission size, current state, etc.


Thanks for the reply.I will be implementing this for a wireless network(WLAN),How do you suggest i can implement the following

-Server announcing its presence via Messages

-I think i cannot use a fixed port number as if any other application is using that port.. it will make the application non usable... what do you think? im i right?

Please advice.
 
Ron McLeod
Saloon Keeper
Posts: 1263
131
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vyshak vijayan wrote:I will be implementing this for a wireless network(WLAN),How do you suggest i can implement the following
   -Server announcing its presence via Messages
   -I think i cannot use a fixed port number as if any other application is using that port.. it will make the application non usable... what do you think? im i right?

If the wireless network is WiFi, then this should work fine; if it is using a cellular data technology, then you will need to use a difference scheme (such as a registry).

Server-side would be something like:
   - Create a DatagramSocket instance
   - Set the broadcast flag for the socket
   - Create a InetAddress instance for the broadcast IP address
   - Create your message
   - Create a DatagramPacket instance, specifying the message, internet address, and broadcast port
   - Send the packet through the socket

Create a separate thread for the announcer, and send the message periodically.

To minimize the chances of a broadcast port conflict with another application/service also using broadcast, avoid choosing a port that is likely to already be used on your network such as ports 67 and 68 used by BOOTP/DHCP, 137 and 138 used by NetBios, etc. You could also include a unique signature in your announcement message which could then be checked by the client-side to verify that the message was for your application.

If you are concerned about conflict with the server listener port, create the listener socket with a dynamically allocated port when the server application first started and and include the port number in your announcement.

Also, if your server application is only going to be able to work with one client at a time (as currently implemented) and the amount of time needed the for the client to complete the submission is significant, you may also want to include a flag in your message indicating the IDLE/BUSY state of the server so that the client can intelligently decide what to do (delay trying to connect to the server; if multiple servers are available, selection one that is IDLE; etc.).
 
vyshak vijayan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ron McLeod wrote:
vyshak vijayan wrote:I will be implementing this for a wireless network(WLAN),How do you suggest i can implement the following
   -Server announcing its presence via Messages
   -I think i cannot use a fixed port number as if any other application is using that port.. it will make the application non usable... what do you think? im i right?

If the wireless network is WiFi, then this should work fine; if it is using a cellular data technology, then you will need to use a difference scheme (such as a registry).

Server-side would be something like:
   - Create a DatagramSocket instance
   - Set the broadcast flag for the socket
   - Create a InetAddress instance for the broadcast IP address
   - Create your message
   - Create a DatagramPacket instance, specifying the message, internet address, and broadcast port
   - Send the packet through the socket

Create a separate thread for the announcer, and send the message periodically.

To minimize the chances of a broadcast port conflict with another application/service also using broadcast, avoid choosing a port that is likely to already be used on your network such as ports 67 and 68 used by BOOTP/DHCP, 137 and 138 used by NetBios, etc. You could also include a unique signature in your announcement message which could then be checked by the client-side to verify that the message was for your application.

If you are concerned about conflict with the server listener port, create the listener socket with a dynamically allocated port when the server application first started and and include the port number in your announcement.

Also, if your server application is only going to be able to work with one client at a time (as currently implemented) and the amount of time needed the for the client to complete the submission is significant, you may also want to include a flag in your message indicating the IDLE/BUSY state of the server so that the client can intelligently decide what to do (delay trying to connect to the server; if multiple servers are available, selection one that is IDLE; etc.).



Thanks a lot for the reply.I will implement the server like this.Yes,actually at a time the server can only serve 1 client.I have seen this example http://www.coderanch.com/t/205709/sockets/java/check-server

After finding all computers in the WLAN i will use this code to check computers one by one for server availability


Which method will be more efficient ?


 
Ron McLeod
Saloon Keeper
Posts: 1263
131
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to be clear -- what I am suggesting is that rather than sequentially probing all the devices in your network, looking for a possible server; that you have the servers periodically announce themselves to the network so that the clients can passively discover them. The amount of time it would take the clients to discover the available servers would be dependent on how often the servers broadcast.

With the probing/scanning technique, the amount of time to discover the servers would be dependent on the size of the network, and the security policies of the devices being probed. For example - some devices may respond right-away with an indication that the port is unreachable. Others however, may not provide any response, causing your to have to wait until the attempt to connect to device eventually times-out. Also, depending on the network security, your repeated (sequential) scans of the network may been seen as a threat, possibly causing the clients searching for the servers to be denied access to the network.
 
vyshak vijayan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for the late reply.Thanks...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!