-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRequestListener.java
39 lines (35 loc) · 933 Bytes
/
RequestListener.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
import java.net.*;
import java.io.*;
/**
* @author David Barts
* @version 0.1
* @since 2016-01-22
*
* Listens for incoming HTTP requests on the loopback interface and spawns
* threads to deal with them.
*/
public class RequestListener extends SaneThread {
private int port;
private PlottableShips ships;
/**
* Constructor.
*
* @return Constructed object.
* @param port Port to listen on.
* @param ships Ships to plot.
*/
public RequestListener(int port, PlottableShips ships) {
setDaemon(true);
this.port = port;
this.ships = ships;
}
void runn() throws Exception {
ServerSocket sock = new ServerSocket(port, 5,
InetAddress.getLoopbackAddress());
while (true) {
Socket conn = sock.accept();
RequestServer server = new RequestServer(conn, ships);
server.start();
}
}
}