Package nxt.peer

Class PeerWebSocket


  • @WebSocket
    public class PeerWebSocket
    extends java.lang.Object
    PeerWebSocket represents an HTTP/HTTPS upgraded connection
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Close the WebSocket
      java.lang.String doPost​(java.lang.String request)
      Process a POST request by sending the request message and then waiting for a response.
      java.net.InetSocketAddress getRemoteAddress()
      Return the remote address for this connection
      boolean isOpen()
      Check if we have a WebSocket connection
      void onClose​(int statusCode, java.lang.String reason)
      WebSocket session has been closed
      void onConnect​(org.eclipse.jetty.websocket.api.Session session)
      WebSocket connection complete
      void onMessage​(byte[] inbuf, int off, int len)
      Process a socket message
      void sendResponse​(long requestId, java.lang.String response)
      Send POST response This method is used by the connection acceptor to return the POST response
      boolean startClient​(java.net.URI uri)
      Start a client session
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • PeerWebSocket

        public PeerWebSocket()
        Create a client socket
      • PeerWebSocket

        public PeerWebSocket​(PeerServlet peerServlet)
        Create a server socket
        Parameters:
        peerServlet - Servlet for request processing
    • Method Detail

      • startClient

        public boolean startClient​(java.net.URI uri)
                            throws java.io.IOException
        Start a client session
        Parameters:
        uri - Server URI
        Returns:
        TRUE if the WebSocket connection was completed
        Throws:
        java.io.IOException - I/O error occurred
      • onConnect

        @OnWebSocketConnect
        public void onConnect​(org.eclipse.jetty.websocket.api.Session session)
        WebSocket connection complete
        Parameters:
        session - WebSocket session
      • isOpen

        public boolean isOpen()
        Check if we have a WebSocket connection
        Returns:
        TRUE if we have a WebSocket connection
      • getRemoteAddress

        public java.net.InetSocketAddress getRemoteAddress()
        Return the remote address for this connection
        Returns:
        Remote address or null if the connection is closed
      • doPost

        public java.lang.String doPost​(java.lang.String request)
                                throws java.io.IOException
        Process a POST request by sending the request message and then waiting for a response. This method is used by the connection originator.
        Parameters:
        request - Request message
        Returns:
        Response message
        Throws:
        java.io.IOException - I/O error occurred
      • sendResponse

        public void sendResponse​(long requestId,
                                 java.lang.String response)
                          throws java.io.IOException
        Send POST response This method is used by the connection acceptor to return the POST response
        Parameters:
        requestId - Request identifier
        response - Response message
        Throws:
        java.io.IOException - I/O error occurred
      • onMessage

        @OnWebSocketMessage
        public void onMessage​(byte[] inbuf,
                              int off,
                              int len)
        Process a socket message
        Parameters:
        inbuf - Message buffer
        off - Starting offset
        len - Message length
      • onClose

        @OnWebSocketClose
        public void onClose​(int statusCode,
                            java.lang.String reason)
        WebSocket session has been closed
        Parameters:
        statusCode - Status code
        reason - Reason message
      • close

        public void close()
        Close the WebSocket