-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServerMain.java
More file actions
48 lines (38 loc) · 1.05 KB
/
Copy pathServerMain.java
File metadata and controls
48 lines (38 loc) · 1.05 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
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
public class ServerMain
{
public static void main(String[] args)
{
ServerSocket serverSocket = null;
try {
serverSocket = new ServerSocket(4242);
System.out.println("Server established");
} catch (IOException e) {
System.out.println("Error establishing server");
e.printStackTrace();
}
System.out.println("Waiting for clients to connect...");
Socket socket = null;
try
{
while (true)
{
socket = serverSocket.accept();
System.out.println("Client accepted");
ServerThread newClient = new ServerThread(socket);
new Thread(newClient).start();
}
} catch (IOException e)
{
e.printStackTrace();
}
try {
serverSocket.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
}