-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
27 lines (22 loc) · 772 Bytes
/
Main.java
File metadata and controls
27 lines (22 loc) · 772 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
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class Main {
public static void main(String[] args) {
System.setProperty("java.net.preferIPv4Stack", "true");
ServerSocket welcomeSocket;
try {
welcomeSocket = new ServerSocket(8080);
ExecutorService executor = Executors.newFixedThreadPool(20);
while (true) {
Socket clientSocket = welcomeSocket.accept(); // Listens for a connection to be made to this socket and accepts it.
Runnable worker = new ConnectionHandler(clientSocket);
executor.execute(worker);
}
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
}