Package me.autobot.lib.server.topica
Class Topica
java.lang.Object
fi.iki.elonen.NanoWSD.WebSocket
me.autobot.lib.server.topica.Topica
public class Topica
extends fi.iki.elonen.NanoWSD.WebSocket
Topica, a topic based server that
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Database for the Topica server, containing all of the different topics.static class
The server for the Topica protocol. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final byte
Type code denoting a boolean.static final byte
Type code denoting a byte list.static final byte
A custom type that has a custom encoding.static final byte
Type code denoting a double.static final byte
Type code denoting a float.static final byte
Type code denoting an integer.static final byte
Type code denoting a long.static final byte
Type code denoting a short.static final byte
Type code denoting a string. -
Constructor Summary
ConstructorsConstructorDescriptionTopica
(fi.iki.elonen.NanoHTTPD.IHTTPSession handshakeRequest) Creates a new Topica WebSocket connection. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
Creates a new Topica database.protected static String
Generates a nicknamestatic Topica.Database
Gets the database of the Topica server.protected static boolean
Returns true or false depending on if the verbose setting is on.protected void
onClose
(fi.iki.elonen.NanoWSD.WebSocketFrame.CloseCode code, String reason, boolean initiatedByRemote) Closes the Topica WebSocket connection.protected void
onException
(IOException exception) Called when an exception occurs.protected void
onMessage
(fi.iki.elonen.NanoWSD.WebSocketFrame message) Handles a message from the Topica WebSocket connection.protected void
onOpen()
Creates a new Topica WebSocket connection.protected void
onPong
(fi.iki.elonen.NanoWSD.WebSocketFrame pong) Called on the pong frame.static void
port
(int port) Assigns the port to a custom port.protected void
sendTopicData
(String topic) Sends the data of a topic to the client.protected void
setTopicData
(String topic, int[] unusedPayload) Sets the data of a topic.static void
start()
Starts a new Topica server on the default port or the custom port.protected void
subscribeToTopic
(String topic, int[] unusedPayload) Subscribes the websocket to a topic.static Topica.Database.Topic
Gets or creates a topic if it does not exist.Methods inherited from class fi.iki.elonen.NanoWSD.WebSocket
close, debugFrameReceived, debugFrameSent, getHandshakeRequest, getHandshakeResponse, isOpen, ping, send, send, sendFrame
-
Field Details
-
BYTE_TYPE
public static final byte BYTE_TYPEType code denoting a byte list.- See Also:
-
SHORT_TYPE
public static final byte SHORT_TYPEType code denoting a short.- See Also:
-
INT_TYPE
public static final byte INT_TYPEType code denoting an integer.- See Also:
-
LONG_TYPE
public static final byte LONG_TYPEType code denoting a long.- See Also:
-
FLOAT_TYPE
public static final byte FLOAT_TYPEType code denoting a float.- See Also:
-
DOUBLE_TYPE
public static final byte DOUBLE_TYPEType code denoting a double.- See Also:
-
STRING_TYPE
public static final byte STRING_TYPEType code denoting a string.- See Also:
-
BOOLEAN_TYPE
public static final byte BOOLEAN_TYPEType code denoting a boolean.- See Also:
-
CUSTOM_TYPE
public static final byte CUSTOM_TYPEA custom type that has a custom encoding. TODO: fix.- See Also:
-
-
Constructor Details
-
Topica
public Topica(fi.iki.elonen.NanoHTTPD.IHTTPSession handshakeRequest) Creates a new Topica WebSocket connection.- Parameters:
handshakeRequest
- The handshake request.
-
-
Method Details
-
port
public static void port(int port) Assigns the port to a custom port.- Parameters:
port
- The port to start the server on.
-
isVerbose
protected static boolean isVerbose()Returns true or false depending on if the verbose setting is on.- Returns:
- If the Topica server is verbose, using /topica/verbose.
-
topic
Gets or creates a topic if it does not exist.- Parameters:
path
- The path of the topic.type
- The type of the topic.
-
createDatabase
public static void createDatabase()Creates a new Topica database. -
start
public static void start()Starts a new Topica server on the default port or the custom port. -
getDatabase
Gets the database of the Topica server.- Returns:
- The database of the Topica server.
-
generateNickname
Generates a nickname- Returns:
- the new nickname
-
onOpen
protected void onOpen()Creates a new Topica WebSocket connection.- Specified by:
onOpen
in classfi.iki.elonen.NanoWSD.WebSocket
-
onClose
protected void onClose(fi.iki.elonen.NanoWSD.WebSocketFrame.CloseCode code, String reason, boolean initiatedByRemote) Closes the Topica WebSocket connection.- Specified by:
onClose
in classfi.iki.elonen.NanoWSD.WebSocket
- Parameters:
code
- The close code.reason
- The reason for closing.initiatedByRemote
- Whether the connection was closed by the remote.
-
onMessage
protected void onMessage(fi.iki.elonen.NanoWSD.WebSocketFrame message) Handles a message from the Topica WebSocket connection.- Specified by:
onMessage
in classfi.iki.elonen.NanoWSD.WebSocket
- Parameters:
message
- The message from the WebSocket.
-
sendTopicData
Sends the data of a topic to the client.- Parameters:
topic
- The topic to send the data of.
-
setTopicData
Sets the data of a topic.- Parameters:
topic
- The topic to set the data of.unusedPayload
- The payload containing the rest of the data request.s
-
subscribeToTopic
Subscribes the websocket to a topic.- Parameters:
topic
- The topic to subscribe to.unusedPayload
- The payload containing the rest of the data request.
-
onPong
protected void onPong(fi.iki.elonen.NanoWSD.WebSocketFrame pong) Called on the pong frame.- Specified by:
onPong
in classfi.iki.elonen.NanoWSD.WebSocket
- Parameters:
pong
- The pong frame.
-
onException
Called when an exception occurs.- Specified by:
onException
in classfi.iki.elonen.NanoWSD.WebSocket
- Parameters:
exception
- The exception that occurred.
-