Package me.autobot.lib.server
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 ClassesModifier and TypeClassDescriptionstatic enum
ClientType is an enum representing the type of client that is connected to the server. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected 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
ConstructorsConstructorDescriptionWSClient
(fi.iki.elonen.NanoHTTPD.IHTTPSession handshake) Creates a new WSClient with a handshake. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
onClose
(fi.iki.elonen.NanoWSD.WebSocketFrame.CloseCode code, String reason, boolean initiatedByRemote) Called when the client is closed.protected void
onException
(IOException exception) Called when an exception occurs.protected void
onMessage
(fi.iki.elonen.NanoWSD.WebSocketFrame message) Called when a message is received.protected void
onOpen()
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
registerSensorConnection
(WSSensorConnection connection) 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
-
Field Details
-
routes
List of all the routes that the clients can use. -
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
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
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 classfi.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 classfi.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 classfi.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 classfi.iki.elonen.NanoWSD.WebSocket
- Parameters:
pong
- The pong that was received.
-
onException
Called when an exception occurs.- Specified by:
onException
in classfi.iki.elonen.NanoWSD.WebSocket
- Parameters:
exception
- The exception that occurred.
-