Class 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)
    • Nested Class Summary

      • Nested classes/interfaces inherited from class com.pusher.java_websocket.server.WebSocketServer

        com.pusher.java_websocket.server.WebSocketServer.WebSocketServerFactory, com.pusher.java_websocket.server.WebSocketServer.WebSocketWorker
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected Actor m_FlowContext
      the flow context.
      protected Logger m_Logger
      for logging purposes.
      • Fields inherited from class com.pusher.java_websocket.server.WebSocketServer

        DECODERS
    • 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 host
      void onMessage​(com.pusher.java_websocket.WebSocket conn, ByteBuffer message)
      Callback for binary messages received from the remote host
      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.
      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
      • Methods inherited from class com.pusher.java_websocket.WebSocketAdapter

        getFlashPolicy, onWebsocketHandshakeReceivedAsClient, onWebsocketHandshakeSentAsClient, onWebsocketPing, onWebsocketPong
    • Field Detail

      • m_Logger

        protected Logger m_Logger
        for logging purposes.
      • m_FlowContext

        protected Actor m_FlowContext
        the flow context.
    • 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

      • getFlowContext

        public Actor getFlowContext()
        Returns the flow context, if any.
        Specified by:
        getFlowContext in interface FlowContextHandler
        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 class com.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 class com.pusher.java_websocket.server.WebSocketServer
        Parameters:
        code - The codes can be looked up here: CloseFrame
        reason - Additional information string
        remote - 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 class com.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 class com.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 class com.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.