-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSlave.java
More file actions
41 lines (32 loc) · 823 Bytes
/
Slave.java
File metadata and controls
41 lines (32 loc) · 823 Bytes
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
import java.io.*;
import java.net.*;
import java.util.Scanner;
public class Slave {
public static void main(String[] args) {
int slaveType = Integer.parseInt(args[0]);
int port = 30123;
try (
Socket slaveSocket = new Socket("localhost", port);
PrintWriter out = new PrintWriter(slaveSocket.getOutputStream(), true);
BufferedReader in = new BufferedReader(new InputStreamReader(slaveSocket.getInputStream()))
) {
Scanner scanner = new Scanner(System.in);
System.out.println("Slave started on port " + port);
} catch (IOException e) {
e.printStackTrace();
}
Thread slave;
switch(slaveType) {
case 1:
slave = new Slave1();
break;
case 2:
slave = new Slave2();
break;
default:
System.out.println("Invalid args.");
return;
}
slave.start();
}
}