Reputation: 1301
Here's what I'm trying to do- A server sends out "Alive message to all the PCs on the network and the PCs which are up and running, respond to the call by sending their IP.
I'm looking at a lightweight piece of coding as this will form a small bit of my application.
I've looked at Jini and other services but find that I may not need even half of their features(except for the network discovery)
Is it ok if I: 1. Use a for loop where a server opens a socket, checks(using a for loop) if all the IPs x.x.x.x are reachable by sending an "Alive" message. 2. On receiving the "alive" message at the client at the specific socket, the client replies with its IP.
Is this method OK? Do you think I could do it in a better way?
Thanks!
Upvotes: 0
Views: 3463
Reputation: 21419
I had a similar problem a long time ago and I resolved it as follows:
The packet I personally used looks like
public class UDPDiscoveryPacket{
public final long sendingTime;
public final String clientIP;
public UDPDiscoveryPacket(long sendingTime, String clientIP){
this.sendingTime = sendingTime;
this.clientIP = clientIP;
}
}
Upvotes: 2