-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClientListener.java
40 lines (35 loc) · 1.1 KB
/
ClientListener.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
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
/**
* Created by sameerraghuram on 4/22/17.
*/
public class ClientListener implements Runnable{
Socket clientSocket = null;
/**
* Sets up and configures a listner on the client
* port for our application (12343).
*
* New connections are handled by the run method.
*/
public void run() {
ServerSocket serverSocket = null;
try {
serverSocket = new ServerSocket(12343);
while (true) {
clientSocket = serverSocket.accept();
System.out.println("Accepted Connection from"+clientSocket.getInetAddress().getCanonicalHostName());
Thread handler = new Thread(new ClientHandler(clientSocket));
handler.start();
}
}
catch (IOException io){
System.err.println("IOExceotion has occured: "+io.getMessage());
}
finally {
System.out.printf("Clean up here");
}
}
}