Class WebSocketMessage


  • public class WebSocketMessage
    extends Object
    • Constructor Detail

      • WebSocketMessage

        public WebSocketMessage()
      • WebSocketMessage

        public WebSocketMessage​(int type)
      • WebSocketMessage

        public WebSocketMessage​(int type,
                                boolean bufferIncludesHeader,
                                byte[] buffer)
      • WebSocketMessage

        public WebSocketMessage​(int type,
                                boolean bufferIncludesHeader,
                                byte[] buffer,
                                int offset,
                                int len)
    • Method Detail

      • createMessagePing

        public static WebSocketMessage createMessagePing​(boolean mask)
        Create a ping message (body will be 8-byte UTC in millseconds)
        Parameters:
        mask - true, to mask message
        Returns:
        WebSocketMessage
      • createMessagePing

        public static WebSocketMessage createMessagePing​(boolean mask,
                                                         byte[] body)
        Create ping message
        Parameters:
        mask - true, to mask message
        body - bytes to include as body of message
        Returns:
        WebSocketMessage
      • createMessagePong

        public static WebSocketMessage createMessagePong​(boolean mask,
                                                         WebSocketMessage messagePing)
        Create pong message
        Parameters:
        mask - true, to mask message
        messagePing - ping message that is source of pong (body copied to pong message)
        Returns:
        WebSocketMessage
      • createMessageClose

        public static WebSocketMessage createMessageClose​(boolean mask,
                                                          int reasonCode,
                                                          String reasonStr)
        Create a close message
        Parameters:
        mask - true, to mask message
        reasonCode - reason code, see IWebSocketSession.CLOSECODE_*
        reasonStr - reason string, see IWebSocketSession.CLOSESTR_*
        Returns:
        WebSocketMessage
      • createMessageText

        public static WebSocketMessage createMessageText​(boolean mask,
                                                         String messageStr)
        Create text message
        Parameters:
        mask - true, to mask message
        messageStr - string data
        Returns:
        WebSocketMessage
      • createMessageBinary

        public static WebSocketMessage createMessageBinary​(boolean mask,
                                                           byte[] buffer,
                                                           int offset,
                                                           int len)
        Create binary message
        Parameters:
        mask - true, to mask message
        buffer - body buffer
        offset - offset into body buffer
        len - len of message
        Returns:
        WebSocketMessage
      • createMessageBinary

        public static WebSocketMessage createMessageBinary​(boolean mask,
                                                           com.wowza.util.IFasterByteArrayOutputStream buffer,
                                                           int offset,
                                                           int len)
        Create binary message
        Parameters:
        mask - true, to mask message
        buffer - body buffer
        offset - offset into body buffer
        len - len of message
        Returns:
        WebSocketMessage
      • createMessageBinary

        public static WebSocketMessage createMessageBinary​(boolean mask,
                                                           byte[] buffer)
        Create binary message
        Parameters:
        mask - true, to mask message
        buffer - body buffer
        Returns:
        WebSocketMessage
      • isControlMessage

        public boolean isControlMessage()
        Is message a control message
        Returns:
        true if control message (ping, ping, close...)
      • addBuffer

        public void addBuffer​(byte[] buffer,
                              int offset,
                              int len,
                              boolean fragmented)
        Used internally to add read TCP bytes into current pending message
        Parameters:
        buffer - buffer
        offset - offset
        len - len
        fragmented - true, if fragmented
      • getType

        public int getType()
        Get message type, see OPCODE_*
        Returns:
        message type
      • isText

        public boolean isText()
        Is message text message
        Returns:
        true if text message
      • isBinary

        public boolean isBinary()
        Is binary message
        Returns:
        true if binary message
      • getCloseReason

        public int getCloseReason()
        If close message, get the close reason
        Returns:
        close reason (-1 if not close message or no reason)
      • getCloseReasonStr

        public String getCloseReasonStr()
        If close message, get the close reason str
        Returns:
        close reason str (null if not close message or no reason)
      • getValueString

        public String getValueString()
        If text message, get body as string
        Returns:
        get body as string
      • getBuffer

        public byte[] getBuffer()
        Get the raw binary message data (also need offset and len)
        Returns:
        raw binary message data
      • getOffset

        public int getOffset()
        Get offset into message buffer
        Returns:
        offset into message buffer
      • getLen

        public int getLen()
        Get len of message buffer data
        Returns:
        len of message buffer data
      • setType

        public void setType​(int type)
        Set message type, see OPCODE_*
        Parameters:
        type - message type
      • sendMessage

        public long sendMessage​(com.wowza.util.IFasterByteArrayWriteReference out)
        Internal method to send message over TCP connection
        Parameters:
        out - writer
        Returns:
        number of bytes written
      • toString

        public String toString()
        Get message as a string (use getValueString() to get the body value of text messages)
        Overrides:
        toString in class Object