-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestServer.java
46 lines (39 loc) · 1.31 KB
/
TestServer.java
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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
public class TestServer {
public static void main(String[] args) throws IOException {
ServerSocket ss = new ServerSocket(80);
while (true) {
Socket client = ss.accept();
System.out.println("Client con!");
new Handler(client).start();
}
}
private static class Handler extends Thread {
private Socket client;
private BufferedReader reader;
private PrintWriter writer;
public Handler(Socket client) throws IOException {
this.client = client;
this.reader = new BufferedReader(new InputStreamReader(this.client.getInputStream()));
this.writer = new PrintWriter(this.client.getOutputStream());
}
@Override
public void run() {
while (true) {
try {
int charInt;
while ((charInt = this.reader.read()) != -1) {
System.out.println(charInt);
}
} catch (IOException e) {
System.out.println("Client closed!");
}
}
}
}
}