简体   繁体   中英

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

您只需创建一个套接字,然后尝试连接到要检查的节点,如果它抛出exception,则表示该节点当前不可访问。

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()));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM