-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerPart2.java
More file actions
28 lines (23 loc) · 901 Bytes
/
Copy pathServerPart2.java
File metadata and controls
28 lines (23 loc) · 901 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
import java.io.*;
import java.net.*;
public class ServerPart2 {
int port = 50001;
public static void main(String[] args) {
ServerPart2 server = new ServerPart2();
server.create_Server();
}
public void create_Server() {
try (ServerSocket serverSocket = new ServerSocket(port)) {
System.out.println("Server is listening on port " + port);
while (true) {
// Listen for a client connection
Socket clientSocket = serverSocket.accept();
System.out.println("Client connected");
// Handle the client in a new thread
new Thread(new ClientHandler(clientSocket)).start();
}
} catch (IOException e) {
throw new RuntimeException("Error while starting the server: " + e.getMessage(), e);
}
}
}