Package adams.flow.websocket.server
Class EchoServer
- java.lang.Object
-
- com.pusher.java_websocket.WebSocketAdapter
-
- com.pusher.java_websocket.server.WebSocketServer
-
- adams.flow.websocket.server.EchoServer
-
- All Implemented Interfaces:
FlowContextHandler,com.pusher.java_websocket.WebSocketListener,Runnable
public class EchoServer extends com.pusher.java_websocket.server.WebSocketServer implements FlowContextHandler
Just sends the messages back to the client.- Version:
- $Revision$
- 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(com.pusher.java_websocket.WebSocket conn, int code, String reason, boolean remote)Called after the websocket connection has been closed.voidonError(com.pusher.java_websocket.WebSocket conn, Exception ex)Called when errors occurs.voidonMessage(com.pusher.java_websocket.WebSocket conn, String message)Callback for string messages received from the remote hostvoidonMessage(com.pusher.java_websocket.WebSocket conn, ByteBuffer message)Callback for binary messages received from the remote hostvoidonOpen(com.pusher.java_websocket.WebSocket conn, com.pusher.java_websocket.handshake.ClientHandshake handshake)Called after an opening handshake has been performed and the given websocket is ready to be written on.voidsetFlowContext(Actor value)Sets the flow context.-
Methods inherited from class com.pusher.java_websocket.server.WebSocketServer
addConnection, allocateBuffers, connections, createBuffer, getAddress, getDraft, getFlashSecurityPolicy, getLocalSocketAddress, getPort, getRemoteSocketAddress, getWebSocketFactory, onCloseInitiated, onClosing, onConnect, onFragment, onWebsocketClose, onWebsocketCloseInitiated, onWebsocketClosing, onWebsocketError, onWebsocketHandshakeReceivedAsServer, onWebsocketMessage, onWebsocketMessage, onWebsocketMessageFragment, onWebsocketOpen, onWriteDemand, releaseBuffers, removeConnection, run, setWebSocketFactory, start, stop, stop
-
-
-
-
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
-
onOpen
public void onOpen(com.pusher.java_websocket.WebSocket conn, com.pusher.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 classcom.pusher.java_websocket.server.WebSocketServer
-
onClose
public void onClose(com.pusher.java_websocket.WebSocket conn, int code, String reason, boolean remote)Called after the websocket connection has been closed.- Specified by:
onClosein classcom.pusher.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(com.pusher.java_websocket.WebSocket conn, String message)Callback for string messages received from the remote host- Specified by:
onMessagein classcom.pusher.java_websocket.server.WebSocketServer
-
onMessage
public void onMessage(com.pusher.java_websocket.WebSocket conn, ByteBuffer message)Callback for binary messages received from the remote host- Overrides:
onMessagein classcom.pusher.java_websocket.server.WebSocketServer
-
onError
public void onError(com.pusher.java_websocket.WebSocket conn, Exception ex)Called when errors occurs.- Specified by:
onErrorin classcom.pusher.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.
-
-