Package com.iizix.jetty
Class WebSocketClientEndPoint
java.lang.Object
com.iizix.jetty.WebSocketClientEndPoint
- All Implemented Interfaces:
- IWebSocketComm,- Session.Listener,- Session.Listener.AutoDemanding
@WebSocket(autoDemand=true) public class WebSocketClientEndPoint extends Object implements IWebSocketComm, Session.Listener.AutoDemanding
Client Endpoint for Jetty 12 WebSocket, with auto-demand for additional messages.
- Nested Class Summary- Nested classes/interfaces inherited from interface org.eclipse.jetty.websocket.api.Session.Listener- Session.Listener.Abstract, Session.Listener.AbstractAutoDemanding, Session.Listener.AutoDemanding
- Method SummaryModifier and TypeMethodDescription- booleanChecks if Binary Data Frames are supported.- void- close()Call this method to close the socket.- boolean- close- (boolean rightNow) Call this method to close the socket.- voidCall this method to close the socket.- void- dispose()Disposes of the session: will soft-close it nicely.Gets the WebSocket attachment object, null for none.Gets the request domain.- int- getPort()Gets the port number for the connection to the server.Returns the Internet Protocol (IP) address of the client or last proxy that sent the request.Returns the fully qualified name of the client or the last proxy that sent the request.Returns the remote address to which this channel's socket is connected.- getState()Gets the state of the connection.Gets the negotiated and accepted sub-protocol, null for none (yet), or none is provided by the parties (server or client).- boolean- isClosed()Checks if the connection is disposed of.- booleanChecks if the connection is currently closing.- booleanFlag for supporting software compression on client side.- booleanChecks if the connection is established.- booleanChecks if the connection is connecting.- boolean- isSecure()Return if the connection is secured using SSL/TLS.- void- onWebSocketBinary- (ByteBuffer buf, Callback callback) Binary message received.- void- onWebSocketClose- (int code, String reason) Called when session is being closed.- voidCalled when session encounters an error.- void- onWebSocketFrame- (Frame frame) A WebSocket PING has been received.- void- onWebSocketOpen- (Session session) Called when session is opened.- voidA WebSocket PONG frame has been received.- void- onWebSocketText- (String message) String message received.- void- open()Opens the communication.- void- send- (byte[] data) Sends binary data.- voidSends a String of data.- booleanSends a heart-beat.- void- setAttachment- (Object attachment) Gets the WebSocket attachment object, null for none.- void- setSubProtocol- (String subProtocol) Assigns a sub-protocol for the WebSocket (in case the processing of sub-protocol negotiation is done e.g.- Methods inherited from class java.lang.Object- clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait- Methods inherited from interface org.eclipse.jetty.websocket.api.Session.Listener- onWebSocketFrame, onWebSocketPartialBinary, onWebSocketPartialText, onWebSocketPing
- Method Details- isCompressionSupportedpublic boolean isCompressionSupported()Flag for supporting software compression on client side.- Specified by:
- isCompressionSupportedin interface- IWebSocketComm
- Returns:
- Always true.
 
- disposepublic void dispose()Disposes of the session: will soft-close it nicely.
- openOpens the communication.- Specified by:
- openin interface- IWebSocketComm
- Throws:
- IOException
 
- getStateGets the state of the connection.- Specified by:
- getStatein interface- IWebSocketComm
- Returns:
- The state.
 
- isConnectingpublic boolean isConnecting()Checks if the connection is connecting.- Specified by:
- isConnectingin interface- IWebSocketComm
- Returns:
- true if the connection is pending.
 
- isConnectedpublic boolean isConnected()Checks if the connection is established.- Specified by:
- isConnectedin interface- IWebSocketComm
- Returns:
- true if the connection is established.
 
- isClosingpublic boolean isClosing()Checks if the connection is currently closing.- Specified by:
- isClosingin interface- IWebSocketComm
- Returns:
- true if not closed, but closing.
 
- isClosedpublic boolean isClosed()Checks if the connection is disposed of.- Specified by:
- isClosedin interface- IWebSocketComm
- Returns:
- true if closed, not closing.
 
- closepublic void close()Call this method to close the socket.- Specified by:
- closein interface- IWebSocketComm
 
- closeCall this method to close the socket.- Specified by:
- closein interface- IWebSocketComm
- Parameters:
- code- A close code: zero for none, otherwise a code 1000 or range 4000 to 4999.
- reason- The reason code, can be null.
 
- closepublic boolean close- (boolean rightNow) Call this method to close the socket.- Specified by:
- closein interface- IWebSocketComm
- Parameters:
- rightNow- If true, the socket is hard-closed, i.e. no close conversation takes place with the server. If false, the client will send a close message to server that replies with a close itself, then the socket is closed.
- Returns:
- true if closed, false if already closed.
 
- setSubProtocolAssigns a sub-protocol for the WebSocket (in case the processing of sub-protocol negotiation is done e.g. outside the WebSocket communication acceptor).- Specified by:
- setSubProtocolin interface- IWebSocketComm
- Throws:
- IllegalStateException- If the state doesn't permit this operation, or if the implementation doesn't allow it.
 
- getSubProtocolGets the negotiated and accepted sub-protocol, null for none (yet), or none is provided by the parties (server or client).- Specified by:
- getSubProtocolin interface- IWebSocketComm
- Returns:
- The String for the sub-protocol negotiated, null for none.
 
- areBinaryDataFramesSupportedpublic boolean areBinaryDataFramesSupported()Checks if Binary Data Frames are supported.- Specified by:
- areBinaryDataFramesSupportedin interface- IWebSocketComm
- Returns:
- true if it is supported, false otherwise.
 
- sendSends binary data.- Specified by:
- sendin interface- IWebSocketComm
- Parameters:
- data- The byte array containing the data.
- Throws:
- IOException- for failures, e.g. socket is closed, not open, not connected.
 
- sendSends a String of data.- Specified by:
- sendin interface- IWebSocketComm
- Parameters:
- data- The String to send.
- Throws:
- IOException- for failures, e.g. socket is closed, not open, not connected.
 
- sendHeartBeatSends a heart-beat.- Specified by:
- sendHeartBeatin interface- IWebSocketComm
- Returns:
- true for success, false for failure (e.g. closing state or closed).
- Throws:
- IOException- For send failures.
 
- getDomainGets the request domain.- Specified by:
- getDomainin interface- IWebSocketComm
- Returns:
- The domain name of the server.
 
- getPortpublic int getPort()Gets the port number for the connection to the server.- Specified by:
- getPortin interface- IWebSocketComm
- Returns:
- The port number.
 
- isSecurepublic boolean isSecure()Return if the connection is secured using SSL/TLS.- Specified by:
- isSecurein interface- IWebSocketComm
- Returns:
- The secure flag. Please note that if the server is behind a proxy, the connection might be secure anyway.
 
- getRemoteAddrReturns the Internet Protocol (IP) address of the client or last proxy that sent the request. For HTTP servlets, same as the value of the CGI variable REMOTE_ADDR. The IP address format depends if it is an IPv4 or IPv6 address.- Specified by:
- getRemoteAddrin interface- IWebSocketComm
- Returns:
- a String containing the IP address of the client that sent the request.
 
- getRemoteHostReturns the fully qualified name of the client or the last proxy that sent the request. If the engine cannot or chooses not to resolve the hostname (to improve performance), this method returns the dotted-string form of the IP address (if IPv4, colon'ed-string for IPv6). For HTTP servlets, same as the value of the CGI variable REMOTE_HOST.- Specified by:
- getRemoteHostin interface- IWebSocketComm
- Returns:
- a String containing the fully qualified name of the client.
 
- getSocketAddressReturns the remote address to which this channel's socket is connected.- Where the channel is bound and connected to an Internet Protocol socket address then the return value from this method is of type - SocketAddress.- Specified by:
- getSocketAddressin interface- IWebSocketComm
- Returns:
- The remote address; nullif the channel's socket is not connected.
 
- getAttachmentGets the WebSocket attachment object, null for none.- Specified by:
- getAttachmentin interface- IWebSocketComm
- Returns:
- An object set by setAttachment.
 
- setAttachmentGets the WebSocket attachment object, null for none.- Specified by:
- setAttachmentin interface- IWebSocketComm
- Parameters:
- attachment- The attachment object for the web socket.
 
- onWebSocketOpenCalled when session is opened.- Specified by:
- onWebSocketOpenin interface- Session.Listener
- Parameters:
- session- The WebSocket session.
 
- onWebSocketErrorCalled when session encounters an error.- Specified by:
- onWebSocketErrorin interface- Session.Listener
 
- onWebSocketCloseCalled when session is being closed.- Specified by:
- onWebSocketClosein interface- Session.Listener
- Parameters:
- code- The close code.
- reason- The reason, or- nullfor none.
 
- onWebSocketPongA WebSocket PONG frame has been received.- Specified by:
- onWebSocketPongin interface- Session.Listener
- Parameters:
- buf- the PONG payload.
 
- onWebSocketFrameA WebSocket PING has been received. Reply with a PONG with the same content.- Parameters:
- buf- the PING payload.
 
- onWebSocketTextString message received.- Specified by:
- onWebSocketTextin interface- Session.Listener
- Parameters:
- message- The string message.
 
- onWebSocketBinaryBinary message received.- Specified by:
- onWebSocketBinaryin interface- Session.Listener
- Parameters:
- buf- The byte buffer with the data.
- callback- Callback when completed.