-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSimpleServer.java
More file actions
executable file
·40 lines (37 loc) · 1.29 KB
/
SimpleServer.java
File metadata and controls
executable file
·40 lines (37 loc) · 1.29 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
public class SimpleServer {
public static void main(String[] args) {
try {
//a socket opened on the specified port
ServerSocket aListeningSocket =
new ServerSocket(9292);
while(true){
//wait for a connection
System.out.println("Waiting for client connection request.");
Socket clientSocket =
aListeningSocket.accept();
//setup the JSON streams for later use.
JSONInputStream inFromClient =
new JSONInputStream(clientSocket.getInputStream());
JSONOutputStream outToClient =
new JSONOutputStream(clientSocket.getOutputStream());
//read until the client closes
//the connection.
while(true){
System.out.println("Waiting for a message from the server.");
HashMap aMap =
(HashMap)inFromClient.readObject();
System.out.println("Just got:"
+aMap+" from client");
CommunicationBean aResponse =
new CommunicationBean("Done",
(ArrayList)aMap.get("data"));
outToClient.writeObject(aResponse);
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.exit(1);
}
}
}