Class WebSocketRemoteEndpoint

  • All Implemented Interfaces:
    RemoteEndpoint

    public class WebSocketRemoteEndpoint
    extends java.lang.Object
    implements RemoteEndpoint
    Endpoint for Writing messages to the Remote websocket.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void flush()
      Flushes messages that may have been batched by the implementation.
      BatchMode getBatchMode()  
      java.net.InetSocketAddress getInetSocketAddress()
      Get the InetSocketAddress for the established connection.
      void sendBytes​(java.nio.ByteBuffer data)
      Blocking write of bytes.
      void sendBytes​(java.nio.ByteBuffer data, WriteCallback callback)
      Initiates the asynchronous transmission of a binary message.
      java.util.concurrent.Future<java.lang.Void> sendBytesByFuture​(java.nio.ByteBuffer data)
      Initiates the asynchronous transmission of a binary message.
      void sendPartialBytes​(java.nio.ByteBuffer fragment, boolean isLast)
      Send a binary message in pieces, blocking until all of the message has been transmitted.
      void sendPartialString​(java.lang.String fragment, boolean isLast)
      Send a text message in pieces, blocking until all of the message has been transmitted.
      void sendPing​(java.nio.ByteBuffer applicationData)
      Send a Ping message containing the given application data to the remote endpoint.
      void sendPong​(java.nio.ByteBuffer applicationData)
      Allows the developer to send an unsolicited Pong message containing the given application data in order to serve as a unidirectional heartbeat for the session.
      void sendString​(java.lang.String text)
      Send a text message, blocking until all bytes of the message has been transmitted.
      void sendString​(java.lang.String text, WriteCallback callback)
      Initiates the asynchronous transmission of a text message.
      java.util.concurrent.Future<java.lang.Void> sendStringByFuture​(java.lang.String text)
      Initiates the asynchronous transmission of a text message.
      void setBatchMode​(BatchMode batchMode)
      Set the batch mode with which messages are sent.
      java.lang.String toString()  
      void uncheckedSendFrame​(WebSocketFrame frame, WriteCallback callback)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Method Detail

      • getInetSocketAddress

        public java.net.InetSocketAddress getInetSocketAddress()
        Get the InetSocketAddress for the established connection.
        Specified by:
        getInetSocketAddress in interface RemoteEndpoint
        Returns:
        the InetSocketAddress for the established connection. (or null, if the connection is no longer established)
      • sendBytes

        public void sendBytes​(java.nio.ByteBuffer data)
                       throws java.io.IOException
        Blocking write of bytes.
        Specified by:
        sendBytes in interface RemoteEndpoint
        Parameters:
        data - the message to be sent
        Throws:
        java.io.IOException - if unable to send the bytes
      • sendBytesByFuture

        public java.util.concurrent.Future<java.lang.Void> sendBytesByFuture​(java.nio.ByteBuffer data)
        Description copied from interface: RemoteEndpoint
        Initiates the asynchronous transmission of a binary message. This method returns before the message is transmitted. Developers may use the returned Future object to track progress of the transmission.
        Specified by:
        sendBytesByFuture in interface RemoteEndpoint
        Parameters:
        data - the data being sent
        Returns:
        the Future object representing the send operation.
      • sendBytes

        public void sendBytes​(java.nio.ByteBuffer data,
                              WriteCallback callback)
        Description copied from interface: RemoteEndpoint
        Initiates the asynchronous transmission of a binary message. This method returns before the message is transmitted. Developers may provide a callback to be notified when the message has been transmitted or resulted in an error.
        Specified by:
        sendBytes in interface RemoteEndpoint
        Parameters:
        data - the data being sent
        callback - callback to notify of success or failure of the write operation
      • sendPartialBytes

        public void sendPartialBytes​(java.nio.ByteBuffer fragment,
                                     boolean isLast)
                              throws java.io.IOException
        Description copied from interface: RemoteEndpoint
        Send a binary message in pieces, blocking until all of the message has been transmitted. The runtime reads the message in order. Non-final pieces are sent with isLast set to false. The final piece must be sent with isLast set to true.
        Specified by:
        sendPartialBytes in interface RemoteEndpoint
        Parameters:
        fragment - the piece of the message being sent
        isLast - true if this is the last piece of the partial bytes
        Throws:
        java.io.IOException - if unable to send the partial bytes
      • sendPartialString

        public void sendPartialString​(java.lang.String fragment,
                                      boolean isLast)
                               throws java.io.IOException
        Description copied from interface: RemoteEndpoint
        Send a text message in pieces, blocking until all of the message has been transmitted. The runtime reads the message in order. Non-final pieces are sent with isLast set to false. The final piece must be sent with isLast set to true.
        Specified by:
        sendPartialString in interface RemoteEndpoint
        Parameters:
        fragment - the piece of the message being sent
        isLast - true if this is the last piece of the partial bytes
        Throws:
        java.io.IOException - if unable to send the partial bytes
      • sendPing

        public void sendPing​(java.nio.ByteBuffer applicationData)
                      throws java.io.IOException
        Description copied from interface: RemoteEndpoint
        Send a Ping message containing the given application data to the remote endpoint. The corresponding Pong message may be picked up using the MessageHandler.Pong handler.
        Specified by:
        sendPing in interface RemoteEndpoint
        Parameters:
        applicationData - the data to be carried in the ping request
        Throws:
        java.io.IOException - if unable to send the ping
      • sendPong

        public void sendPong​(java.nio.ByteBuffer applicationData)
                      throws java.io.IOException
        Description copied from interface: RemoteEndpoint
        Allows the developer to send an unsolicited Pong message containing the given application data in order to serve as a unidirectional heartbeat for the session.
        Specified by:
        sendPong in interface RemoteEndpoint
        Parameters:
        applicationData - the application data to be carried in the pong response.
        Throws:
        java.io.IOException - if unable to send the pong
      • sendString

        public void sendString​(java.lang.String text)
                        throws java.io.IOException
        Description copied from interface: RemoteEndpoint
        Send a text message, blocking until all bytes of the message has been transmitted.

        Note: this is a blocking call

        Specified by:
        sendString in interface RemoteEndpoint
        Parameters:
        text - the message to be sent
        Throws:
        java.io.IOException - if unable to send the text message
      • sendStringByFuture

        public java.util.concurrent.Future<java.lang.Void> sendStringByFuture​(java.lang.String text)
        Description copied from interface: RemoteEndpoint
        Initiates the asynchronous transmission of a text message. This method may return before the message is transmitted. Developers may use the returned Future object to track progress of the transmission.
        Specified by:
        sendStringByFuture in interface RemoteEndpoint
        Parameters:
        text - the text being sent
        Returns:
        the Future object representing the send operation.
      • sendString

        public void sendString​(java.lang.String text,
                               WriteCallback callback)
        Description copied from interface: RemoteEndpoint
        Initiates the asynchronous transmission of a text message. This method may return before the message is transmitted. Developers may provide a callback to be notified when the message has been transmitted or resulted in an error.
        Specified by:
        sendString in interface RemoteEndpoint
        Parameters:
        text - the text being sent
        callback - callback to notify of success or failure of the write operation
      • flush

        public void flush()
                   throws java.io.IOException
        Description copied from interface: RemoteEndpoint
        Flushes messages that may have been batched by the implementation.
        Specified by:
        flush in interface RemoteEndpoint
        Throws:
        java.io.IOException - if the flush fails
        See Also:
        RemoteEndpoint.getBatchMode()
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object