-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvkServerThread.java
37 lines (32 loc) · 1.2 KB
/
vkServerThread.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
import java.net.*;
import java.io.*;
public class vkServerThread extends Thread {
private Socket clientSocket = null;
public vkServerThread(Socket socket) {
super("vkServerMultiThread");
this.clientSocket = socket;
}
public void run() {
try (
PrintWriter out =
new PrintWriter(clientSocket.getOutputStream(), true); //Message that want to send to client
BufferedReader in = new BufferedReader(
new InputStreamReader(clientSocket.getInputStream())); //Message that received from client
) {
String inputLine, outputLine;
// Initiate conversation with client
vkProtocol protocol = new vkProtocol();
outputLine = protocol.processInput(null);
out.println(outputLine);
while ((inputLine = in.readLine()) != null) {
outputLine = protocol.processInput(inputLine);
out.println(outputLine);
if (outputLine.equals("Bye."))
break;
}
} catch (IOException e) {
System.out.println("Exception caught when trying to listen on port or listening for a connection");
System.out.println(e.getMessage());
}
}
}