Package 

Class WebSocketImpl

  • All Implemented Interfaces:
    com.tds.common.websocket.conn.WebSocket

    
    public class WebSocketImpl
     implements WebSocket
                        

    Represents one end (client or server) of a single WebSocketImpl connection. Takes care of the "handshake" phase, then allows for easy sending of text frames, and receiving frames through an event-based model.

    • Constructor Detail

      • WebSocketImpl

        WebSocketImpl(WebSocketListener listener, List<Draft> drafts)
        Creates a websocket with server role
        Parameters:
        listener - The listener for this instance
        drafts - The drafts which should be used
      • WebSocketImpl

        WebSocketImpl(WebSocketListener listener, Draft draft)
        creates a websocket with client role
        Parameters:
        listener - The listener for this instance
        draft - The draft which should be used
    • Method Detail

      • getReadyState

         ReadyState getReadyState()

        Retrieve the WebSocket 'ReadyState'. This represents the state of the connection. It returns anumerical value, as per W3C WebSockets specs.

      • getResourceDescriptor

         String getResourceDescriptor()

        Returns the HTTP Request-URI as defined by http://tools.ietf.org/html/rfc2616#section-5.1.2If the opening handshake has not yet happened it will return null.

      • setAttachment

         <T> void setAttachment(T attachment)

        Setter for an attachment on the socket connection. The attachment may be of any type.

        Parameters:
        attachment - The object to be attached to the user
      • decode

         void decode(ByteBuffer socketBuffer)

        Method to decode the provided ByteBuffer

        Parameters:
        socketBuffer - the ByteBuffer to decode
      • close

         synchronized void close(int code, String message, boolean remote)
      • close

         void close(int code, String message)

        sends the closing handshake. may be send in response to an other handshake.

        Parameters:
        code - the closing code
        message - the closing message
      • closeConnection

         synchronized void closeConnection(int code, String message, boolean remote)

        This will close the connection immediately without a proper close handshake. The code and themessage therefore won't be transferred over the wire also they will be forwarded toonClose/onWebsocketClose.

        Parameters:
        code - the closing code
        message - the closing message
        remote - Indicates who "generated" code.
      • closeConnection

         void closeConnection(int code, String message)

        This will close the connection immediately without a proper close handshake. The code and themessage therefore won't be transferred over the wire also they will be forwarded toonClose/onWebsocketClose.

        Parameters:
        code - the closing code
        message - the closing message
      • eot

         void eot()
      • close

         void close(int code)

        sends the closing handshake. may be send in response to an other handshake.

        Parameters:
        code - the closing code
      • send

         void send(String text)

        Send Text data to the other end.

      • send

         void send(ByteBuffer bytes)

        Send Binary data (plain bytes) to the other end.

      • send

         void send(Array<byte> bytes)

        Send Binary data (plain bytes) to the other end.

        Parameters:
        bytes - the byte array to send
      • sendFragmentedFrame

         void sendFragmentedFrame(Opcode op, ByteBuffer buffer, boolean fin)

        Allows to send continuous/fragmented frames conveniently. For more into on this frame typesee http://tools.ietf.org/html/rfc6455#section-5.4

        If the first frame you send is also the last then it is not a fragmented frame and willreceived via onMessage instead of onFragmented even though it was send by this method.

        Parameters:
        op - This is only important for the first frame in the sequence.
        buffer - The buffer which contains the payload.
        fin - true means the current frame is the last in the sequence.
      • sendFrame

         void sendFrame(Collection<Framedata> frames)

        Send a collection of frames to the other end

        Parameters:
        frames - the frames to send to the other end
      • sendFrame

         void sendFrame(Framedata framedata)

        Send a frame to the other end

        Parameters:
        framedata - the frame to send to the other end
      • sendPing

         void sendPing()

        Send a ping to the other end

      • hasBufferedData

         boolean hasBufferedData()

        Checks if the websocket has buffered data

      • isOpen

         boolean isOpen()

        Is the websocket in the state OPEN

      • isClosing

         boolean isClosing()

        Is the websocket in the state CLOSING

      • isFlushAndClose

         boolean isFlushAndClose()

        Returns true when no further frames may be submitted This happens before the socketconnection is closed.

      • isClosed

         boolean isClosed()

        Is the websocket in the state CLOSED

      • close

         void close()

        Convenience function which behaves like close(CloseFrame.NORMAL)

      • updateLastPong

         void updateLastPong()

        Update the timestamp when the last pong was received

      • hasSSLSupport

         boolean hasSSLSupport()

        Does this websocket use an encrypted (wss/ssl) or unencrypted (ws) connection

      • getSSLSession

         SSLSession getSSLSession()

        Returns the ssl session of websocket, if ssl/wss is used for this instance.

      • getProtocol

         IProtocol getProtocol()

        Returns the used Sec-WebSocket-Protocol for this websocket connection