-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFileReceiver.java
55 lines (48 loc) · 1.4 KB
/
FileReceiver.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
import java.io.*;
import java.net.*;
public class FileReceiver extends ThreadedRunnable {
/**
* Properties
*/
private DatagramSocket socket;
/**
* Constructor
*/
public FileReceiver(int port) throws SocketException {
// Create listening socket
this.socket = new DatagramSocket(port);
}
/**
* ThreadedRunnable's implementation
*/
@Override
public void run() {
// TODO: Code this part
}
/**Main executable method*/
public static void main(String[] args) {
// Check arguments length
if (args.length != 1) {
printInstructions();
System.exit(1);
}
// Check arguments validity
try {
// Create address
FileReceiver receiver = new FileReceiver(Integer.parseInt(args[0]));
receiver.join();
} catch (NumberFormatException e) {
printInstructions();
System.exit(1);
} catch (IOException|SecurityException e) {
System.out.printf("Error: Cannot create socket at port %s\n", args[0]);
System.exit(1);
} catch (InterruptedException e) {
System.out.println("Error: Main thread was interrupted");
System.exit(1);
}
}
private static void printInstructions() {
System.out.println("Usage: java FileReceiver <port>");
}
}