-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOneAction.java
42 lines (36 loc) · 918 Bytes
/
OneAction.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import java.net.*;
class OneAction {
private Target server;
private String hostStr;
private int order;
private boolean reachable = false;
private Socket socket;
private int timeout;
private long start, duration;
OneAction(Target target, int tm) {
this.timeout = tm;
this.server = target;
this.socket = new Socket();
}
public void exec() {
// socket = new Socket();
hostStr = server.getAddress().getHostString();
order = server.getOrder();
start = System.currentTimeMillis();
try {
try {
socket.connect(server.getAddress(), timeout);
} finally {
socket.close();
}
duration = (System.currentTimeMillis() - start);
System.out.printf("%5d %5d ms %s%n", order, duration, hostStr );
reachable = true;
} catch (Exception e) {
reachable = false;
}
if (!reachable) {
System.out.println(String.format("\t%s was UNREACHABLE", hostStr));
}
}
}