-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlayer.java
More file actions
42 lines (32 loc) · 1.1 KB
/
Player.java
File metadata and controls
42 lines (32 loc) · 1.1 KB
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
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 Player {
public static void main(String[] args) {
try (ServerSocket serverSocket = new ServerSocket(8082);
Socket clientSocket = serverSocket.accept();
PrintWriter out = new PrintWriter(
clientSocket.getOutputStream(), true);
BufferedReader in = new BufferedReader(new InputStreamReader(
clientSocket.getInputStream()));) {
String inputLine, outputLine;
// Initiate conversation with client
GameProtocol kkp = new GameProtocol();
outputLine = kkp.processInput(null);
out.println(outputLine);
while ((inputLine = in.readLine()) != null) {
outputLine = kkp.processInput(inputLine);
out.println(outputLine);
if (outputLine.equals("Bye."))
break;
}
// Client
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}