-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTCPServerEchoThread.java
49 lines (36 loc) · 1.23 KB
/
TCPServerEchoThread.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
47
48
49
import java.io.*;
import java.net.*;
public class TCPServerEchoThread extends Thread {
private Socket socket;
public TCPServerEchoThread(Socket socket) {
super();
this.socket = socket;
}
public void run() {
// System.setProperty("line.separator", "\r\n"); // Mac users only
String thread_ID = Long.toString(currentThread().getId());
System.out.println("THREAD " + thread_ID + " entering");
try {
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
out.println("s20946");
out.println("336089");
String n = null;
String x = null;
n = in.readLine();
x = in.readLine();
System.out.println(n + " : " + x);
out.println(n + x);
} catch (IOException e1) {
System.out.println("No I/O");
// do nothing
}
try {
socket.close();
} catch (IOException e) {
System.out.println("No I/O");
// do nothing
}
System.out.println("THREAD " + thread_ID + " exiting");
}
}