Class WSClient

java.lang.Object
fi.iki.elonen.NanoWSD.WebSocket
me.autobot.lib.server.WSClient

public class WSClient extends fi.iki.elonen.NanoWSD.WebSocket
A websocket client class that is used to communicate with the client.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    ClientType is an enum representing the type of client that is connected to the server.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static ArrayList<WSClientRoute>
    List of all the routes that the clients can use.
    protected static ArrayList<WSSensorConnection>
    List of all the sensor connections that the clients can use.
  • Constructor Summary

    Constructors
    Constructor
    Description
    WSClient(fi.iki.elonen.NanoHTTPD.IHTTPSession handshake)
    Creates a new WSClient with a handshake.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    onClose(fi.iki.elonen.NanoWSD.WebSocketFrame.CloseCode code, String reason, boolean initiatedByRemote)
    Called when the client is closed.
    protected void
    Called when an exception occurs.
    protected void
    onMessage(fi.iki.elonen.NanoWSD.WebSocketFrame message)
    Called when a message is received.
    protected void
    Called when the client is opened.
    protected void
    onPong(fi.iki.elonen.NanoWSD.WebSocketFrame pong)
    Called when a pong is received.
    static void
    registerCallable(int address, Runnable runnable)
    Register a callable with an address (will be called by the client if specified).
    static void
    Register a sensor connection with the client.
    void
    sendSensorData(byte robotAddress, byte sensorAddress, double[] values)
    Sends sensor data to the client.
    void
    sendValues(byte type, byte address, byte address2, byte... payload)
    Sends values to the client.

    Methods inherited from class fi.iki.elonen.NanoWSD.WebSocket

    close, debugFrameReceived, debugFrameSent, getHandshakeRequest, getHandshakeResponse, isOpen, ping, send, send, sendFrame

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • routes

      protected static ArrayList<WSClientRoute> routes
      List of all the routes that the clients can use.
    • sensorConnections

      protected static ArrayList<WSSensorConnection> sensorConnections
      List of all the sensor connections that the clients can use.
  • Constructor Details

    • WSClient

      public WSClient(fi.iki.elonen.NanoHTTPD.IHTTPSession handshake)
      Creates a new WSClient with a handshake.
      Parameters:
      handshake - The handshake to create the client with.
  • Method Details

    • registerCallable

      public static void registerCallable(int address, Runnable runnable)
      Register a callable with an address (will be called by the client if specified).
      Parameters:
      address - The address of the callable.
      runnable - The runnable to run when the callable is called.
    • registerSensorConnection

      public static void registerSensorConnection(WSSensorConnection connection)
      Register a sensor connection with the client.
      Parameters:
      connection - The connection to register.
    • onOpen

      protected void onOpen()
      Called when the client is opened.
      Specified by:
      onOpen in class fi.iki.elonen.NanoWSD.WebSocket
    • onClose

      protected void onClose(fi.iki.elonen.NanoWSD.WebSocketFrame.CloseCode code, String reason, boolean initiatedByRemote)
      Called when the client is closed.
      Specified by:
      onClose in class fi.iki.elonen.NanoWSD.WebSocket
      Parameters:
      code - The code of the close.
      reason - The reason of the close.
      initiatedByRemote - Whether the close was initiated by the remote client.
    • onMessage

      protected void onMessage(fi.iki.elonen.NanoWSD.WebSocketFrame message)
      Called when a message is received.
      Specified by:
      onMessage in class fi.iki.elonen.NanoWSD.WebSocket
      Parameters:
      message - The message that was received.
    • sendSensorData

      public void sendSensorData(byte robotAddress, byte sensorAddress, double[] values)
      Sends sensor data to the client.
      Parameters:
      robotAddress - The address of the robot.
      sensorAddress - The address of the sensor.
      values - The values to send.
    • sendValues

      public void sendValues(byte type, byte address, byte address2, byte... payload)
      Sends values to the client.
      Parameters:
      type - The type of the values.
      address - The first address (typically the robot address)
      address2 - The second address (typically the sensor address)
      payload - The payload to send.
    • onPong

      protected void onPong(fi.iki.elonen.NanoWSD.WebSocketFrame pong)
      Called when a pong is received.
      Specified by:
      onPong in class fi.iki.elonen.NanoWSD.WebSocket
      Parameters:
      pong - The pong that was received.
    • onException

      protected void onException(IOException exception)
      Called when an exception occurs.
      Specified by:
      onException in class fi.iki.elonen.NanoWSD.WebSocket
      Parameters:
      exception - The exception that occurred.