Package 

Class RealWebSocket

  • All Implemented Interfaces:
    com.mobwith.httpmodule.WebSocket , com.mobwith.httpmodule.internal.ws.WebSocketReader.FrameCallback

    
    public final class RealWebSocket
     implements WebSocket, WebSocketReader.FrameCallback
                        
    • Method Detail

      • request

         MobonRequest request()

        Returns the original mobonRequest that initiated this web socket.

      • queueSize

         synchronized long queueSize()

        Returns the size in bytes of all messages enqueued to be transmitted to the server. Thisdoesn't include framing overhead. It also doesn't include any bytes buffered by the operatingsystem or network intermediaries. This method returns 0 if no messages are waitingin the queue. If may return a nonzero value after the web socket has been canceled; thisindicates that enqueued messages were not transmitted.

      • cancel

         void cancel()

        Immediately and violently release resources held by this web socket, discarding any enqueuedmessages. This does nothing if the web socket has already been closed or canceled.

      • loopReader

         void loopReader()

        Receive frames until there are no more. Invoked only by the reader thread.

      • send

         boolean send(String text)

        Attempts to enqueue {@code text} to be UTF-8 encoded and sent as a the data of a text (type {@code 0x1}) message.

        This method returns true if the message was enqueued. Messages that would overflow theoutgoing message buffer will be rejected and trigger a graceful shutdown ofthis web socket. This method returns false in that case, and in any other case where thisweb socket is closing, closed, or canceled.

        This method returns immediately.

      • send

         boolean send(ByteString bytes)

        Attempts to enqueue {@code bytes} to be sent as a the data of a binary (type {@code 0x2})message.

        This method returns true if the message was enqueued. Messages that would overflow theoutgoing message buffer (16 MiB) will be rejected and trigger a graceful shutdown of this web socket. This method returns false in thatcase, and in any other case where this web socket is closing, closed, or canceled.

        This method returns immediately.

      • close

         boolean close(int code, String reason)

        Attempts to initiate a graceful shutdown of this web socket. Any already-enqueued messages willbe transmitted before the close message is sent but subsequent calls to send willreturn false and their messages will not be enqueued.

        This returns true if a graceful shutdown was initiated by this call. It returns false and ifa graceful shutdown was already underway or if the web socket is already closed or canceled.

        Parameters:
        code - Status code as defined by Section 7.4 of RFC 6455.
        reason - Reason for shutting down or {@code null}.