Package adams.flow.websocket.server
Class EchoServer
- java.lang.Object
-
- org.java_websocket.WebSocketAdapter
-
- org.java_websocket.AbstractWebSocket
-
- org.java_websocket.server.WebSocketServer
-
- adams.flow.websocket.server.EchoServer
-
- All Implemented Interfaces:
FlowContextHandler,Runnable,org.java_websocket.WebSocketListener
public class EchoServer extends org.java_websocket.server.WebSocketServer implements FlowContextHandler
Just sends the messages back to the client.- Author:
- FracPete (fracpete at waikato dot ac dot nz)
-
-
Field Summary
Fields Modifier and Type Field Description protected Actorm_FlowContextthe flow context.protected Loggerm_Loggerfor logging purposes.
-
Constructor Summary
Constructors Constructor Description EchoServer(InetSocketAddress address, Logger logger)Instantiates the server with the given address.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ActorgetFlowContext()Returns the flow context, if any.protected LoggergetLogger()Returns the logger instance to use.voidonClose(org.java_websocket.WebSocket conn, int code, String reason, boolean remote)Called after the websocket connection has been closed.voidonError(org.java_websocket.WebSocket conn, Exception ex)Called when errors occurs.voidonMessage(org.java_websocket.WebSocket conn, String message)Callback for string messages received from the remote hostvoidonMessage(org.java_websocket.WebSocket conn, ByteBuffer message)Callback for binary messages received from the remote hostvoidonOpen(org.java_websocket.WebSocket conn, org.java_websocket.handshake.ClientHandshake handshake)Called after an opening handshake has been performed and the given websocket is ready to be written on.voidonStart()Called after the server starts.voidsetFlowContext(Actor value)Sets the flow context.-
Methods inherited from class org.java_websocket.server.WebSocketServer
addConnection, allocateBuffers, broadcast, broadcast, broadcast, broadcast, broadcast, broadcast, createBuffer, getAddress, getConnections, getDraft, getLocalSocketAddress, getMaxPendingConnections, getPort, getRemoteSocketAddress, getWebSocketFactory, onCloseInitiated, onClosing, onConnect, onWebsocketClose, onWebsocketCloseInitiated, onWebsocketClosing, onWebsocketError, onWebsocketMessage, onWebsocketMessage, onWebsocketOpen, onWriteDemand, queue, releaseBuffers, removeConnection, run, setDaemon, setMaxPendingConnections, setWebSocketFactory, start, stop, stop, stop
-
Methods inherited from class org.java_websocket.AbstractWebSocket
getConnectionLostTimeout, getReceiveBufferSize, isDaemon, isReuseAddr, isTcpNoDelay, setConnectionLostTimeout, setReceiveBufferSize, setReuseAddr, setTcpNoDelay, startConnectionLostTimer, stopConnectionLostTimer
-
-
-
-
Constructor Detail
-
EchoServer
public EchoServer(InetSocketAddress address, Logger logger)
Instantiates the server with the given address.- Parameters:
address- the address to bind to
-
-
Method Detail
-
setFlowContext
public void setFlowContext(Actor value)
Sets the flow context.- Specified by:
setFlowContextin interfaceFlowContextHandler- Parameters:
value- the actor
-
getFlowContext
public Actor getFlowContext()
Returns the flow context, if any.- Specified by:
getFlowContextin interfaceFlowContextHandler- Returns:
- the actor, null if none available
-
getLogger
protected Logger getLogger()
Returns the logger instance to use.- Returns:
- the logger
-
onStart
public void onStart()
Called after the server starts.- Specified by:
onStartin classorg.java_websocket.server.WebSocketServer
-
onOpen
public void onOpen(org.java_websocket.WebSocket conn, org.java_websocket.handshake.ClientHandshake handshake)Called after an opening handshake has been performed and the given websocket is ready to be written on.- Specified by:
onOpenin classorg.java_websocket.server.WebSocketServer
-
onClose
public void onClose(org.java_websocket.WebSocket conn, int code, String reason, boolean remote)Called after the websocket connection has been closed.- Specified by:
onClosein classorg.java_websocket.server.WebSocketServer- Parameters:
code- The codes can be looked up here:CloseFramereason- Additional information stringremote- Returns whether or not the closing of the connection was initiated by the remote host.
-
onMessage
public void onMessage(org.java_websocket.WebSocket conn, String message)Callback for string messages received from the remote host- Specified by:
onMessagein classorg.java_websocket.server.WebSocketServer
-
onMessage
public void onMessage(org.java_websocket.WebSocket conn, ByteBuffer message)Callback for binary messages received from the remote host- Overrides:
onMessagein classorg.java_websocket.server.WebSocketServer
-
onError
public void onError(org.java_websocket.WebSocket conn, Exception ex)Called when errors occurs.- Specified by:
onErrorin classorg.java_websocket.server.WebSocketServer- Parameters:
conn- Can be null if there error does not belong to one specific websocket. For example if the servers port could not be bound.
-
-