-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiClienttoClient(Server.java)
More file actions
53 lines (44 loc) · 1.33 KB
/
Copy pathMultiClienttoClient(Server.java)
File metadata and controls
53 lines (44 loc) · 1.33 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package Server;
import Client.ClientHandler;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
public class Server {
public ServerSocket serverSocket;
public Socket socket;
ClientHandler clientHandler;
Server(ServerSocket serverSocket){
this.serverSocket = serverSocket;
}
private void clientConnection(){
try{
while (!serverSocket.isClosed()){
this.socket = serverSocket.accept();
System.out.println("A new Client has connected");
clientHandler = new ClientHandler(this.socket);
Thread serverThread = new Thread(clientHandler);
serverThread.start();
}
} catch (IOException e){
e.printStackTrace();
}
}
private void closeServerSocket(){
if (serverSocket != null) {
try {
serverSocket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
try {
ServerSocket serverSocket = new ServerSocket(5001);
Server server = new Server(serverSocket);
server.clientConnection();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}