-
Notifications
You must be signed in to change notification settings - Fork 4
/
ServerThread.java
50 lines (44 loc) · 1.17 KB
/
ServerThread.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
50
import java.io.*;
import java.net.*;
class ServerThread extends Thread
{
private Socket myDataSocket;
private Socket otherDataSocket;
private InputStream is;
private BufferedReader in;
private OutputStream os;
private PrintWriter out;
private static final String EXIT = "CLOSE";
public ServerThread(Socket socket1, Socket socket2)
{
myDataSocket = socket1;
otherDataSocket = socket2;
try {
is = myDataSocket.getInputStream();
in = new BufferedReader(new InputStreamReader(is));
os = otherDataSocket.getOutputStream();
out = new PrintWriter(os,true);
}
catch (IOException e) {
System.out.println("I/O Error " + e);
}
}
public void run()
{
String inmsg, outmsg;
try {
inmsg = in.readLine();
ServerProtocol app = new ServerProtocol();
outmsg = app.processRequest(inmsg);
while(!outmsg.equals(EXIT)) {
out.println(outmsg);
inmsg = in.readLine();
outmsg = app.processRequest(inmsg);
}
myDataSocket.close();
System.out.println("Data socket closed");
} catch (IOException e) {
System.out.println("I/O Error " + e);
}
}
}