Class ClientWebSocketHandler

java.lang.Object
net.targetr.rc.client.ClientWebSocketHandler
All Implemented Interfaces:
SocketExceptionHandler

public class ClientWebSocketHandler extends Object implements SocketExceptionHandler
Communicates with a client using a WebSocket.
Author:
Dr Michael Gardiner
  • Field Details

    • IDLE_PERIOD

      public static final long IDLE_PERIOD
      Maximum 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

      public static final AtomicInteger clientCount
      Counter for connected clients.
  • Constructor Details

    • ClientWebSocketHandler

      public ClientWebSocketHandler(HttpRequest httpReq)
      Constructs a new WebSocket handler for the given request.
      Parameters:
      httpReq - the incoming HTTP upgrade request
  • Method Details

    • generateResponse

      public HttpResponse generateResponse() throws IOException, NoSuchAlgorithmException
      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 fails
      NoSuchAlgorithmException - if handshake hashing fails
    • handleException

      public void handleException(Exception ex)
      Description copied from interface: SocketExceptionHandler
      Called by HttpHandler when an I/O failure occurs and a response has this handler.
      Specified by:
      handleException in interface SocketExceptionHandler
      Parameters:
      ex - an exception occurred while sending data to client.