-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTCPSocket.java
71 lines (60 loc) · 2.35 KB
/
TCPSocket.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
59
60
61
62
63
64
65
66
67
68
69
70
71
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.DigestInputStream;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public abstract class TCPSocket implements CongestionWindowPlotter {
public TCPSocket(String ip, int port) throws Exception {
}
public abstract void send(String pathToFile) throws Exception;
public final void sendAndLog(String pathToFile) throws Exception {
Path filePath = Paths.get(pathToFile);
String fileName = filePath.getFileName().toString();
long fileSize = Files.size(filePath);
System.err.println(
String.format(
"Starting to send file \"%s\" with size of %d[byte] ...",
fileName,
fileSize
)
);
long sendBeginTime = System.currentTimeMillis();
send(pathToFile);
System.err.println(
String.format(
"File \"%s\" with size of %d[byte] sent in %d[ms].",
fileName,
fileSize,
System.currentTimeMillis() - sendBeginTime
)
);
}
public abstract void receive(String pathToFile) throws Exception;
public final void receiveAndLog(String pathToFile) throws Exception {
Path filePath = Paths.get(pathToFile);
String fileName = filePath.getFileName().toString();
System.err.println(
String.format(
"Starting to receive file \"%s\" ...",
fileName
)
);
long receiveBeginTime = System.currentTimeMillis();
receive(pathToFile);
long receiveEndTime = System.currentTimeMillis();
long fileSize = Files.size(filePath);
System.err.println(
String.format(
"File \"%s\" with size of %d[byte] received in %d[ms].",
fileName,
fileSize,
receiveEndTime - receiveBeginTime
)
);
}
public abstract void close() throws Exception;
}