-
Notifications
You must be signed in to change notification settings - Fork 2
/
Server.java
38 lines (26 loc) · 876 Bytes
/
Server.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
import java.io.*;
import java.net.*;
import java.util.Scanner;
public class Server {
public static void main(String argv[]) throws Exception {
//Handles clients
final ClientHandler clientHandler = new ClientHandler();
final Log log = new Log(clientHandler.queue);
//processing packets if queue is not empty
Thread logThread = new Thread(log);
logThread.start();
//setup the sockets
ServerSocket welcomeSocket = new ServerSocket(9001);
Socket clientSocket = null;
while(true) {
//Connect new clients
clientSocket = welcomeSocket.accept();
System.out.println("SERVER: New client connection");
//Create service to handle client
ClientService clientService = new ClientService(clientSocket, clientHandler);
//Create new thread to run service
Thread thread = new Thread(clientService);
thread.start();
}
} //end main
}