what quickest proceed detect an unreachable horde java?
i fastest many accurate duty boolean isreachable(string host, int port) passes following junit tests underneath conditions below. timeout values specified junit exam itself, competence deliberate "unreachable."
please note: answers contingency platform-independent. means inetaddress.isreachable(int timeout) going work, given relies pier 7 ping windows (icmp ping being an undocumented duty windows), pier blocked setup.
lan setup:
thismachine(192.168.0.100)othermachine(192.168.0.200)- no accessory called
nomachineip192.168.0.222(always unreachable) - both machines controlling apache tomcat pier
8080; ports unreachable (including pier7) example.com(208.77.188.166) controlling webserver pier80wholly reachable lan connected internet
occasionally, lan away internet box wholly internal machines called ip castle reachable (all others unreachable; there's dns).
all tests run thismachine.
@test(timeout=1600) // ~320ms per (should illusory better)
public vacant testlocalhost() {
// always strech ourselves.
asserttrue(isreachable("localhost", 8080));
asserttrue(isreachable("127.0.0.1", 8080));
asserttrue(isreachable("thismachine", 8080)); // even there's dns!
asserttrue(isreachable("192.168.0.100", 8080));
assertfalse(isreachable("localhost", 80)); // zero port.
}
@test(timeout=5500) // ~1867ms per (should means better)
public vacant testlan() {
asserttrue(isreachable("192.168.0.200", 8080)); // always connected lan.
assertfalse(isreachable("192.168.0.222", 8080)); // such machine.
assertfalse(isreachable("nomachine", 8080)); // such machine.
}
the following exam wholly run lan disconnected internet.
@test(timeout=5600) // ~1867ms per (reasonable?)
public vacant testnodns() {
assertfalse(isreachable("othermachine", 8080)); // dns.
assertfalse(isreachable("example.com", 80)); // dns & internet.
assertfalse(isreachable("208.77.188.166", 80)); // internet.
}
the following exam wholly run lan connected internet.
@test(timeout=5600) // ~1867ms per (reasonable?)
public vacant testhavedns() {
asserttrue(isreachable("othermachine", 8080)); // dns resolves internal names.
asserttrue(isreachable("example.com", 80)); // dns available.
asserttrue(isreachable("208.77.188.166", 80)); // internet available.
}
Comments
Post a Comment