我尝试使用以下代码行 ping 作为我自己的 PC 的服务器:
InetAddress.getByName(serverResourceLocator).isReachable(5000)
// where serverResourceLocator is 192.168.43.187/server/ping?ip=Adarsh-PC/192.168.43.187&time=1355482205301
这192.168.43.187
是我的 PC 的网络 IP,我从命令中得知ipconfig
Wireless LAN adapter Wireless Network Connection:
Connection-specific DNS Suffix . :
Link-local IPv6 Address . . . . . : fe80::f5be:cfa7:5c38:efff%14
IPv4 Address. . . . . . . . . . . : 192.168.43.187
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.43.1
在我的 PC 上,我正在运行 tomcat 作为服务器。为什么我会得到UnknownHostException
?
java.net.UnknownHostException: 192.168.43.187/server/ping?ip=Adarsh-PC/192.168.43.187&time=1355482205301
at java.net.InetAddress.getAllByName0(InetAddress.java:1140)
at java.net.InetAddress.getAllByName0(InetAddress.java:1109)
at java.net.InetAddress.getAllByName(InetAddress.java:1072)
at java.net.InetAddress.getByName(InetAddress.java:969)
at internet.CommunicationWithServer.PingTheServer.ping(PingTheServer.java:35)
at internet.CommunicationWithServer.PingTheServer.access$000(PingTheServer.java:11)
at internet.CommunicationWithServer.PingTheServer$1.run(PingTheServer.java:21)
at java.lang.Thread.run(Thread.java:619)