Class WebSocket

    • Field Detail

      • logger

        protected static final org.slf4j.Logger logger
      • WEBSOCKET_INITIATED

        public static final java.lang.String WEBSOCKET_INITIATED
      • WEBSOCKET_SUSPEND

        public static final java.lang.String WEBSOCKET_SUSPEND
      • WEBSOCKET_RESUME

        public static final java.lang.String WEBSOCKET_RESUME
      • WEBSOCKET_ACCEPT_DONE

        public static final java.lang.String WEBSOCKET_ACCEPT_DONE
      • lastWrite

        protected long lastWrite
      • binaryWrite

        protected boolean binaryWrite
      • bb

        protected java.nio.ByteBuffer bb
      • cb

        protected java.nio.CharBuffer cb
      • uuid

        protected java.lang.String uuid
    • Method Detail

      • binaryWrite

        public WebSocket binaryWrite​(boolean binaryWrite)
        Switch to binary write, or go back to text write. Default is false.
        Parameters:
        binaryWrite - true to switch to binary write.
        Returns:
        WebSocket
      • attributes

        public java.util.Map<java.lang.String,​java.lang.Object> attributes()
        Return the attribute that was set during the websocket's open operation.
        Returns:
        Map
      • lastWriteTimeStampInMilliseconds

        public long lastWriteTimeStampInMilliseconds()
        The last time, in milliseconds, a write operation occurred.
        Returns:
        this
      • transform

        protected byte[] transform​(byte[] b,
                                   int offset,
                                   int length)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • transform

        protected byte[] transform​(AtmosphereResponse response,
                                   byte[] b,
                                   int offset,
                                   int length)
                            throws java.io.IOException
        Throws:
        java.io.IOException
      • broadcast

        public WebSocket broadcast​(java.lang.Object o)
        Broadcast, using the AtmosphereResource.getBroadcaster() the object to all WebSocket associated with the Broadcaster. This method does the same as websocket.resource().getBroadcaster().broadcast(o).
        Parameters:
        o - An object to broadcast to all WebSockets.
      • isOpen

        public abstract boolean isOpen()
        Is the underlying WebSocket open.
        Returns:
        true is opened
      • write

        public abstract WebSocket write​(java.lang.String s)
                                 throws java.io.IOException
        Use the underlying container's websocket to write the String.
        Parameters:
        s - a websocket String message
        Returns:
        this
        Throws:
        java.io.IOException
      • write

        public abstract WebSocket write​(byte[] b,
                                        int offset,
                                        int length)
                                 throws java.io.IOException
        Use the underlying container's websocket to write the byte.
        Parameters:
        b - a websocket byte message
        offset - start
        length - end
        Returns:
        this
        Throws:
        java.io.IOException
      • write

        public WebSocket write​(byte[] b)
                        throws java.io.IOException
        Use the underlying container's websocket to write the byte.
        Parameters:
        b - a websocket byte message
        Returns:
        WebSocket
        Throws:
        java.io.IOException
      • close

        public abstract void close()
        Close the underlying WebSocket
      • close

        public void close​(int statusCode,
                          java.lang.String reasonText)
        Allow the underlying WebSocket to close with a code and a reason.
      • uuid

        public java.lang.String uuid()
      • sendPing

        public WebSocket sendPing​(byte[] payload)
        Send a WebSocket Ping
        Parameters:
        payload - the bytes to send
        Returns:
        this
      • sendPong

        public WebSocket sendPong​(byte[] payload)
        Send a WebSocket Pong
        Parameters:
        payload - the bytes to send
        Returns:
        this
      • attachment

        public WebSocket attachment​(java.lang.Object attachment)
        Attach an object. Be careful when attaching an object as it can cause memory leak
      • attachment

        public java.lang.Object attachment()
        Return the attachment