-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClient.java
More file actions
65 lines (56 loc) · 1.84 KB
/
Client.java
File metadata and controls
65 lines (56 loc) · 1.84 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import java.net.InetAddress;
import java.util.Random;
import java.util.function.LongUnaryOperator;
public class Client {
MPSock mpSock;
Random randGen;
public Client() {
randGen = new Random(42);
}
public void run(String[] args) {
int targBytes;
if (args.length > 0){
targBytes = Integer.parseInt(args[0]);
} else {
targBytes = 10000;
}
int numPaths;
if (args.length > 1){
numPaths = Integer.parseInt(args[1]);
} else {
numPaths = 1;
}
int v;
if (args.length > 2){
v = Integer.parseInt(args[2]);
} else {
v = 0;
}
boolean added = false;
try {
mpSock = new MPSock(InetAddress.getByName("127.0.0.1"), 4444, v);
mpSock.connect(InetAddress.getByName("127.0.0.1"), 4445); // always hitting the welcome socket!
for(int i = 0; i < numPaths - 1; i++){
mpSock.addSubflow(InetAddress.getByName("10.0.0.1"), 8001 + i, InetAddress.getByName("127.0.0.1"), 4445);
}
int bytesSent = 0;
while (bytesSent < targBytes) {
int randSize = Math.min(randGen.nextInt(400), targBytes - bytesSent);
byte[] message = new byte[randSize];
for (int j = 0; j < randSize; j++) {
message[j] = (byte) ((bytesSent + j) % 128);
}
int bytesWritten = mpSock.write(message, 0, randSize);
bytesSent += bytesWritten;
}
mpSock.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
Client client = new Client();
client.run(args);
System.out.println("finished!");
}
}