-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathIntgenClient.java
More file actions
46 lines (38 loc) · 1.17 KB
/
Copy pathIntgenClient.java
File metadata and controls
46 lines (38 loc) · 1.17 KB
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
43
44
45
46
import java.nio.*;
import java.nio.channels.*;
import java.net.*;
import java.io.IOException;
public class IntgenClient {
public static int DEFAULT_PORT = 1919;
public static void main(String[] args) {
if (args.length == 0) {
System.out.println("Usage: java IntgenClient host [port]");
return;
}
int port;
try {
port = Integer.parseInt(args[1]);
} catch (RuntimeException ex) {
port = DEFAULT_PORT;
}
try {
SocketAddress address = new InetSocketAddress(args[0], port);
SocketChannel client = SocketChannel.open(address);
ByteBuffer buffer = ByteBuffer.allocate(4);
IntBuffer view = buffer.asIntBuffer();
for (int expected = 0; ; expected++) {
client.read(buffer);
int actual = view.get();
buffer.clear();
view.rewind();
if (actual != expected) {
System.err.println("Expected " + expected + "; was " + actual);
break;
}
System.out.println(actual);
}
} catch(IOException ex) {
ex.printStackTrace();
}
}
}