Deepti
Deepti

Reputation: 41

networking in java

I want to check whether a machine is in the network or not using ip address, and I used

if (InetAddress.getByName(ip).isReachable(3000))

but by using this my complete project has become very slow even if an ip is reachable. After sometime it shows that it is not responding. Is there any alternative to this method?

Thanks

Upvotes: 1

Views: 216

Answers (2)

Yogesh Prajapati
Yogesh Prajapati

Reputation: 4870

I have same problem, but I am using another alternative solution if you are using Windows OS. Simply ping to that IP address ping is respond in millisecond so your app need not wait.

if ping is respond with Respond texxt than do your stuff. Sample code:

Process p = Runtime.getRuntime().exec(new String[]{"ping", your_ip_address});
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));

Upvotes: 0

Don Chakkappan
Don Chakkappan

Reputation: 7560

You just create a socket and try to connect to the node you want to check, if it throws exception , it means that node is currently unreachable.

Upvotes: 1

Related Questions