Package nxt.peer
Class PeerWebSocket
- java.lang.Object
-
- nxt.peer.PeerWebSocket
-
@WebSocket public class PeerWebSocket extends java.lang.Object
PeerWebSocket represents an HTTP/HTTPS upgraded connection
-
-
Constructor Summary
Constructors Constructor Description PeerWebSocket()
Create a client socketPeerWebSocket(PeerServlet peerServlet)
Create a server socket
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close the WebSocketjava.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 connectionboolean
isOpen()
Check if we have a WebSocket connectionvoid
onClose(int statusCode, java.lang.String reason)
WebSocket session has been closedvoid
onConnect(org.eclipse.jetty.websocket.api.Session session)
WebSocket connection completevoid
onMessage(byte[] inbuf, int off, int len)
Process a socket messagevoid
sendResponse(long requestId, java.lang.String response)
Send POST response This method is used by the connection acceptor to return the POST responseboolean
startClient(java.net.URI uri)
Start a client session
-
-
-
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 identifierresponse
- 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 bufferoff
- Starting offsetlen
- Message length
-
onClose
@OnWebSocketClose public void onClose(int statusCode, java.lang.String reason)
WebSocket session has been closed- Parameters:
statusCode
- Status codereason
- Reason message
-
close
public void close()
Close the WebSocket
-
-