i write a piece of code
Socket theSock = new Socket();
try {
byte[] addr = { 127, 0, 0, 1 };
InetAddress addr1 = InetAddress.getByAddress(addr);
//part1
System.out.print(addr1.isReachable(1000));
SocketAddress sockaddr = new InetSocketAddress(addr1, 7);
//part2
theSock.connect(sockaddr, 1000);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (theSock != null) {
try {
theSock.close();
} catch (IOException e) {
}
}
the result is quite intresting, in part 1 Reachable told me "true" but
in part 2 thrown out an Exception "java.net.ConnectException: Connection refused: connect.." . is there any guy could tell me how could that happen. any reponse will be appreciate
>
> the result is quite intresting, in part 1 Reachable
> told me "true" but
> in part 2 thrown out an Exception
> "java.net.ConnectException: Connection refused:
> connect.." . is there any guy could tell me how could
> that happen. any reponse will be appreciate
If the connection is refused then the host was found aka the host was reachable.