Interface WebSocket

    • Field Detail

      • DEFAULT_PORT

        static final int DEFAULT_PORT
        The default port of WebSockets, as defined in the spec. If the nullary constructor is used, DEFAULT_PORT will be the port the WebSocketServer is binded to. Note that ports under 1024 usually require root permissions.
        See Also:
        Constant Field Values
      • DEFAULT_WSS_PORT

        static final int DEFAULT_WSS_PORT
        The default wss port of WebSockets, as defined in the spec. If the nullary constructor is used, DEFAULT_WSS_PORT will be the port the WebSocketServer is binded to. Note that ports under 1024 usually require root permissions.
        See Also:
        Constant Field Values
    • Method Detail

      • 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
      • close

        void close​(int code)
        sends the closing handshake. may be send in response to an other handshake.
        Parameters:
        code - the closing code
      • close

        void close()
        Convenience function which behaves like close(CloseFrame.NORMAL)
      • closeConnection

        void closeConnection​(int code,
                             String message)
        This will close the connection immediately without a proper close handshake. The code and the message therefore won't be transfered over the wire also they will be forwarded to onClose/onWebsocketClose.
        Parameters:
        code - the closing code
        message - the closing message
      • sendFrame

        void sendFrame​(Framedata framedata)
        Send a frame to the other end
        Parameters:
        framedata - the frame to send to the other end
      • 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
      • sendFragmentedFrame

        void sendFragmentedFrame​(Framedata.Opcode op,
                                 ByteBuffer buffer,
                                 boolean fin)
        Allows to send continuous/fragmented frames conveniently.
        For more into on this frame type see 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 will received 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. Opcode.TEXT, Opcode.BINARY are allowed.
        buffer - The buffer which contains the payload. It may have no bytes remaining.
        fin - true means the current frame is the last in the sequence.
      • hasBufferedData

        boolean hasBufferedData()
        Checks if the websocket has buffered data
        Returns:
        has the websocket buffered data
      • getRemoteSocketAddress

        InetSocketAddress getRemoteSocketAddress()
        Returns the address of the endpoint this socket is connected to, ornull if it is unconnected.
        Returns:
        never returns null
      • getLocalSocketAddress

        InetSocketAddress getLocalSocketAddress()
        Returns the address of the endpoint this socket is bound to.
        Returns:
        never returns null
      • isConnecting

        @Deprecated
        boolean isConnecting()
        Deprecated.
        Is the websocket in the state CONNECTING
        Returns:
        state equals READYSTATE.CONNECTING
      • isOpen

        boolean isOpen()
        Is the websocket in the state OPEN
        Returns:
        state equals READYSTATE.OPEN
      • isClosing

        boolean isClosing()
        Is the websocket in the state CLOSING
        Returns:
        state equals READYSTATE.CLOSING
      • isFlushAndClose

        boolean isFlushAndClose()
        Returns true when no further frames may be submitted
        This happens before the socket connection is closed.
        Returns:
        true when no further frames may be submitted
      • isClosed

        boolean isClosed()
        Is the websocket in the state CLOSED
        Returns:
        state equals READYSTATE.CLOSED
      • getDraft

        Draft getDraft()
        Getter for the draft
        Returns:
        the used draft
      • getReadyState

        WebSocket.READYSTATE getReadyState()
        Retrieve the WebSocket 'readyState'. This represents the state of the connection. It returns a numerical value, as per W3C WebSockets specs.
        Returns:
        Returns '0 = CONNECTING', '1 = OPEN', '2 = CLOSING' or '3 = CLOSED'
      • getResourceDescriptor

        String getResourceDescriptor()
        Returns the HTTP Request-URI as defined by http://tools.ietf.org/html/rfc2616#section-5.1.2
        If the opening handshake has not yet happened it will return null.
        Returns:
        Returns the decoded path component of this URI.
      • setAttachment

        <T> void setAttachment​(T attachment)
        Setter for an attachment on the socket connection. The attachment may be of any type.
        Type Parameters:
        T - The type of the attachment
        Parameters:
        attachment - The object to be attached to the user
        Since:
        1.3.7
      • getAttachment

        <T> T getAttachment()
        Getter for the connection attachment.
        Type Parameters:
        T - The type of the attachment
        Returns:
        Returns the user attachment
        Since:
        1.3.7