-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathServerInput.java
More file actions
33 lines (30 loc) · 969 Bytes
/
ServerInput.java
File metadata and controls
33 lines (30 loc) · 969 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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class ServerInput extends Thread {
// Buffered reader to take user input from server console
BufferedReader userIn = new BufferedReader(new InputStreamReader(System.in));
ChatServer server;
// constructor to initialise the server in this class so I can call killthreads()
public ServerInput(ChatServer server) {
this.server = server;
}
public void run() {
try {
// Read user input line by line
while (true) {
String command = userIn.readLine();
// If the user enters the quit command then the threads are killed and the
// program exits
if (command.equals("QUIT")) {
// calls the method to kill threads then exits
server.killThreads();
System.exit(0);
}
}
} catch (IOException e) {
e.printStackTrace();
System.out.println("Could not read from server console");
}
}
}