-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainClass.java
More file actions
32 lines (25 loc) · 1.03 KB
/
MainClass.java
File metadata and controls
32 lines (25 loc) · 1.03 KB
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
import java.io.IOException;
import java.net.*;
import java.util.*;
public class MainClass {
public static void main(String[] args) {
List<Socket> clientSocketList = Collections.synchronizedList(new LinkedList<>());
try (ServerSocket server = new ServerSocket(8188)) {
System.out.println("Server is listening on port 8188...");
while (true) {
// Accept new client connections
Socket clientSocket = server.accept();
System.out.println("New client connected");
// Add the new client socket to the list
clientSocketList.add(clientSocket);
// Start a new thread to handle the client connection
//Thread has List of clients and current client.
Runnable r = new ThreadedServer(clientSocketList, clientSocket);
Thread t = new Thread(r);
t.start();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}