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 classDatabase for the Topica server, containing all of the different topics.static classThe server for the Topica protocol. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final byteType code denoting a boolean.static final byteType code denoting a byte list.static final byteA custom type that has a custom encoding.static final byteType code denoting a double.static final byteType code denoting a float.static final byteType code denoting an integer.static final byteType code denoting a long.static final byteType code denoting a short.static final byteType code denoting a string. -
Constructor Summary
ConstructorsConstructorDescriptionTopica(fi.iki.elonen.NanoHTTPD.IHTTPSession handshakeRequest) Creates a new Topica WebSocket connection. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidCreates a new Topica database.protected static StringGenerates a nicknamestatic Topica.DatabaseGets the database of the Topica server.protected static booleanReturns true or false depending on if the verbose setting is on.protected voidonClose(fi.iki.elonen.NanoWSD.WebSocketFrame.CloseCode code, String reason, boolean initiatedByRemote) Closes the Topica WebSocket connection.protected voidonException(IOException exception) Called when an exception occurs.protected voidonMessage(fi.iki.elonen.NanoWSD.WebSocketFrame message) Handles a message from the Topica WebSocket connection.protected voidonOpen()Creates a new Topica WebSocket connection.protected voidonPong(fi.iki.elonen.NanoWSD.WebSocketFrame pong) Called on the pong frame.static voidport(int port) Assigns the port to a custom port.protected voidsendTopicData(String topic) Sends the data of a topic to the client.protected voidsetTopicData(String topic, int[] unusedPayload) Sets the data of a topic.static voidstart()Starts a new Topica server on the default port or the custom port.protected voidsubscribeToTopic(String topic, int[] unusedPayload) Subscribes the websocket to a topic.static Topica.Database.TopicGets 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:
onOpenin 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:
onClosein 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:
onMessagein 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:
onPongin classfi.iki.elonen.NanoWSD.WebSocket- Parameters:
pong- The pong frame.
-
onException
Called when an exception occurs.- Specified by:
onExceptionin classfi.iki.elonen.NanoWSD.WebSocket- Parameters:
exception- The exception that occurred.
-