-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExampleClient.java
58 lines (50 loc) · 1.96 KB
/
ExampleClient.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package se.umu.cs._5dv186.a1.client;
import java.io.IOException;
import java.net.SocketTimeoutException;
import ki.types.ds.Block;
import ki.types.ds.StreamInfo;
public final class ExampleClient {
public static final int DEFAULT_TIMEOUT = 1000;
//----------------------------------------------------------
//----------------------------------------------------------
public static void listStreamInfo (StreamServiceClient client)
throws IOException {
StreamInfo[] streams = client.listStreams();
System.out.println("found " + streams.length + " streams");
for (StreamInfo stream : streams) {
System.out.println(" '" + stream.getName() + "': " + stream.getLengthInFrames() + " frames, " +
stream.getWidthInBlocks() + " x " + stream.getHeightInBlocks() + " blocks");
}
}
//----------------------------------------------------------
public static void main (String[] args) {
try {
final String host = (args.length > 0) ? args[0] : "localhost";
final int timeout = (args.length > 1) ? Integer.parseInt(args[1]) : DEFAULT_TIMEOUT;
final String username = (args.length > 2) ? args[2] : "test";
StreamServiceClient client = DefaultStreamServiceClient.bind(host,timeout,username);
listStreamInfo(client);
int nr = 100;
int count = 0;
String stream = "stream1";
int frame = 0;
int blockX = 0;
int blockY = 0;
for (int i=0; i<nr; i++) {
try {
long t1 = System.currentTimeMillis();
Block block = client.getBlock(stream,frame,blockX,blockY);
long t2 = System.currentTimeMillis();
System.out.println("block received from server in " + (t2 - t1) + " ms");
count++;
}
catch (SocketTimeoutException e) {
System.out.println("socket timeout");
}
}
System.out.println("received " + count + " / " + nr);
} catch (Exception e) {
e.printStackTrace();
}
}
}