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 Actor
m_FlowContext
the flow context.protected Logger
m_Logger
for 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 Actor
getFlowContext()
Returns the flow context, if any.protected Logger
getLogger()
Returns the logger instance to use.void
onClose(com.pusher.java_websocket.WebSocket conn, int code, String reason, boolean remote)
Called after the websocket connection has been closed.void
onError(com.pusher.java_websocket.WebSocket conn, Exception ex)
Called when errors occurs.void
onMessage(com.pusher.java_websocket.WebSocket conn, String message)
Callback for string messages received from the remote hostvoid
onMessage(com.pusher.java_websocket.WebSocket conn, ByteBuffer message)
Callback for binary messages received from the remote hostvoid
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.void
setFlowContext(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:
setFlowContext
in interfaceFlowContextHandler
- Parameters:
value
- the actor
-
getFlowContext
public Actor getFlowContext()
Returns the flow context, if any.- Specified by:
getFlowContext
in 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:
onOpen
in 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:
onClose
in classcom.pusher.java_websocket.server.WebSocketServer
- Parameters:
code
- The codes can be looked up here:CloseFrame
reason
- 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:
onMessage
in 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:
onMessage
in classcom.pusher.java_websocket.server.WebSocketServer
-
onError
public void onError(com.pusher.java_websocket.WebSocket conn, Exception ex)
Called when errors occurs.- Specified by:
onError
in 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.
-
-