blob: 44a5e9c77344b6f9052d8059cb11cd7173e4d5f1 (
plain)
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
|
package fi.iki.elonen;
public class NanoWebSocketServer extends NanoHTTPD implements WebSocketFactory {
private final WebSocketResponseHandler responseHandler;
public NanoWebSocketServer(int port) {
super(port);
responseHandler = new WebSocketResponseHandler(this);
}
public NanoWebSocketServer(String hostname, int port) {
super(hostname, port);
responseHandler = new WebSocketResponseHandler(this);
}
public NanoWebSocketServer(int port, WebSocketFactory webSocketFactory) {
super(port);
responseHandler = new WebSocketResponseHandler(webSocketFactory);
}
public NanoWebSocketServer(String hostname, int port,WebSocketFactory webSocketFactory) {
super(hostname, port);
responseHandler = new WebSocketResponseHandler(webSocketFactory);
}
@Override
public Response serve(IHTTPSession session) {
Response candidate = responseHandler.serve(session);
return candidate == null ? super.serve(session) : candidate;
}
public WebSocket openWebSocket(IHTTPSession handshake) {
throw new Error("You must either override this method or supply a WebSocketFactory in the cosntructor");
}
}
|