-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
43 lines (35 loc) · 990 Bytes
/
Main.java
File metadata and controls
43 lines (35 loc) · 990 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import java.io.IOException;
import java.io.PrintStream;
import java.net.ServerSocket;
import java.net.Socket;
public class Main {
public static void main(String[] args) {
new Main();
}
public Main() {
try {
ServerSocket serverSocket = new ServerSocket(5000);
while (true) {
System.out.println("Waiting for a new client");
Socket clientSocket = serverSocket.accept();
Runnable runnable = () -> {
PrintStream out;
try {
out = new PrintStream(clientSocket.getOutputStream());
out.println("Hello, World");
out.close();
clientSocket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
};
Thread thread = new Thread(runnable);
thread.start();
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}