Package net.targetr.rc.client
Class ClientWebSocketHandler
java.lang.Object
net.targetr.rc.client.ClientWebSocketHandler
- All Implemented Interfaces:
SocketExceptionHandler
Communicates with a client using a WebSocket.
- Author:
- Dr Michael Gardiner
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final AtomicIntegerCounter for connected clients.static final longMaximum idle period before checking connection status. -
Constructor Summary
ConstructorsConstructorDescriptionClientWebSocketHandler(HttpRequest httpReq) Constructs a new WebSocket handler for the given request. -
Method Summary
Modifier and TypeMethodDescriptionValidates the client request and prepares the response that will perform the WebSocket upgrade and manage the connection when written.voidCalled by HttpHandler when an I/O failure occurs and a response has this handler.
-
Field Details
-
IDLE_PERIOD
public static final long IDLE_PERIODMaximum idle period before checking connection status. Mobile devices may disconnect after 30 seconds of inactivity, so we send a no-op command every 29.5 seconds.- See Also:
-
clientCount
Counter for connected clients.
-
-
Constructor Details
-
ClientWebSocketHandler
Constructs a new WebSocket handler for the given request.- Parameters:
httpReq- the incoming HTTP upgrade request
-
-
Method Details
-
generateResponse
Validates the client request and prepares the response that will perform the WebSocket upgrade and manage the connection when written.- Returns:
- an upgrade response, a room-full notification and close response, or an HTTP error for an invalid request
- Throws:
IOException- if network communication failsNoSuchAlgorithmException- if handshake hashing fails
-
handleException
Description copied from interface:SocketExceptionHandlerCalled by HttpHandler when an I/O failure occurs and a response has this handler.- Specified by:
handleExceptionin interfaceSocketExceptionHandler- Parameters:
ex- an exception occurred while sending data to client.
-