Class InternalWebSocket
- All Implemented Interfaces:
IWebSocketComm,Session.Listener,Session.Listener.AutoDemanding
- Author:
- Christopher Mindus
Nested Class Summary
Nested classes/interfaces inherited from interface org.eclipse.jetty.websocket.api.Session.Listener
Session.Listener.Abstract, Session.Listener.AbstractAutoDemanding, Session.Listener.AutoDemandingMethod Summary
Modifier and TypeMethodDescriptionbooleanChecks if Binary Data Frames are supported.voidclose()Call this method to close the socket.booleanclose(boolean rightNow) Call this method to close the socket.voidCall this method to close the socket.Gets the WebSocket attachment object, null for none.Gets the request domain.intgetPort()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).booleanisClosed()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.booleanisSecure()Return if the connection is secured using SSL/TLS.voidonWebSocketBinary(ByteBuffer buf, Callback callback) A WebSocket BINARY message has been received.voidonWebSocketClose(int code, String reason) The WebSocketSessionhas been closed.voidonWebSocketError(Throwable error) A WebSocket error has occurred during the processing of WebSocket frames.voidonWebSocketOpen(Session session) A WebSocketSessionhas opened successfully and is ready to be used.voidA WebSocket PING frame has been received.voidA WebSocket PONG frame has been received.voidonWebSocketText(String text) A WebSocket TEXT message has been received.voidopen()Opens the communication.voidsend(byte[] data) Sends binary data.voidSends a String of data.booleanSends a heart-beat.voidsetAttachment(Object attachment) Gets the WebSocket attachment object, null for none.voidsetListener(WebSocketCommListener listener) Assigns the listener.voidsetSubProtocol(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, waitMethods inherited from interface org.eclipse.jetty.websocket.api.Session.Listener
onWebSocketClose, onWebSocketFrame, onWebSocketPartialBinary, onWebSocketPartialText
Method Details
open
Opens the communication.- Specified by:
openin interfaceIWebSocketComm- Throws:
IOException
getState
Gets the state of the connection.- Specified by:
getStatein interfaceIWebSocketComm- Returns:
- The state.
getDomain
Gets the request domain.- Specified by:
getDomainin interfaceIWebSocketComm- Returns:
- The domain name of the server.
getPort
public int getPort()Gets the port number for the connection to the server.- Specified by:
getPortin interfaceIWebSocketComm- Returns:
- The port number.
isSecure
public boolean isSecure()Return if the connection is secured using SSL/TLS.- Specified by:
isSecurein interfaceIWebSocketComm- Returns:
- The secure flag. Please note that if the server is behind a proxy, the connection might be secure anyway.
setListener
Assigns the listener.onWebSocketOpen
A WebSocket
Sessionhas opened successfully and is ready to be used.Applications can store the given
Sessionas a field so it can be used to send messages back to the other peer.- Specified by:
onWebSocketOpenin interfaceSession.Listener- Parameters:
session- the WebSocket session
onWebSocketBinary
A WebSocket BINARY message has been received.
- Specified by:
onWebSocketBinaryin interfaceSession.Listener- Parameters:
buf- The raw payload array receivedcallback- The callback to complete when the payload has been processed
onWebSocketText
A WebSocket TEXT message has been received.
- Specified by:
onWebSocketTextin interfaceSession.Listener- Parameters:
text- The text payload.
onWebSocketClose
The WebSocket
Sessionhas been closed.- Specified by:
onWebSocketClosein interfaceSession.Listener- Parameters:
reason- The optional reason for the close.statusCode- The close status code.
onWebSocketError
A WebSocket error has occurred during the processing of WebSocket frames.
Usually errors occurs from bad or malformed incoming packets, for example text frames that do not contain UTF-8 bytes, frames that are too big, or other violations of the WebSocket specification.
The WebSocket
Sessionwill be closed, but applications may explicitlyclosetheSessionproviding a different status code or reason.- Specified by:
onWebSocketErrorin interfaceSession.Listener- Parameters:
error- The error that occurred.
onWebSocketPing
A WebSocket PING frame has been received.
- Specified by:
onWebSocketPingin interfaceSession.Listener- Parameters:
payload- the PING payload
onWebSocketPong
A WebSocket PONG frame has been received.
- Specified by:
onWebSocketPongin interfaceSession.Listener- Parameters:
buf- The PONG payload.
isConnecting
public boolean isConnecting()Checks if the connection is connecting.- Specified by:
isConnectingin interfaceIWebSocketComm- Returns:
- true if the connection is pending.
isConnected
public boolean isConnected()Checks if the connection is established.- Specified by:
isConnectedin interfaceIWebSocketComm- Returns:
- true if the connection is established.
isClosing
public boolean isClosing()Checks if the connection is currently closing.- Specified by:
isClosingin interfaceIWebSocketComm- Returns:
- true if not closed, but closing.
isClosed
public boolean isClosed()Checks if the connection is disposed of.- Specified by:
isClosedin interfaceIWebSocketComm- Returns:
- true if closed, not closing.
close
public void close()Call this method to close the socket.- Specified by:
closein interfaceIWebSocketComm
close
Call this method to close the socket.- Specified by:
closein interfaceIWebSocketComm- Parameters:
code- A close code: zero for none, otherwise a code 1000 or range 3000 to 4999.reason- The reason code: ifcodeis zero, null applies.
close
public boolean close(boolean rightNow) Call this method to close the socket.- Specified by:
closein interfaceIWebSocketComm- 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.
setSubProtocol
Assigns 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 interfaceIWebSocketComm- Throws:
IllegalStateException- If the state doesn't permit this operation, or if the implementation doesn't allow it.
getSubProtocol
Gets the negotiated and accepted sub-protocol, null for none (yet), or none is provided by the parties (server or client).- Specified by:
getSubProtocolin interfaceIWebSocketComm- Returns:
- The String for the sub-protocol negotiated, null for none.
areBinaryDataFramesSupported
public boolean areBinaryDataFramesSupported()Checks if Binary Data Frames are supported.- Specified by:
areBinaryDataFramesSupportedin interfaceIWebSocketComm- Returns:
- true if it is supported, false otherwise.
send
Sends binary data.- Specified by:
sendin interfaceIWebSocketComm- Parameters:
data- The byte array containing the data.- Throws:
IOException- for failures, e.g. socket is closed, not open, not connected.
send
Sends a String of data.- Specified by:
sendin interfaceIWebSocketComm- Parameters:
data- The String to send.- Throws:
IOException- for failures, e.g. socket is closed, not open, not connected.
sendHeartBeat
Sends a heart-beat.- Specified by:
sendHeartBeatin interfaceIWebSocketComm- Returns:
- true for success, false for failure (e.g. closing state or closed).
- Throws:
IOException- For send failures.
getRemoteAddr
Returns 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 interfaceIWebSocketComm- Returns:
- a String containing the IP address of the client that sent the request.
getRemoteHost
Returns 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 interfaceIWebSocketComm- Returns:
- a String containing the fully qualified name of the client.
getSocketAddress
Returns 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
InetSocketAddress.- Specified by:
getSocketAddressin interfaceIWebSocketComm- Returns:
- The remote address;
nullif the channel's socket is not connected.
getAttachment
Gets the WebSocket attachment object, null for none.- Specified by:
getAttachmentin interfaceIWebSocketComm- Returns:
- An object set by
setAttachment.
setAttachment
Gets the WebSocket attachment object, null for none.- Specified by:
setAttachmentin interfaceIWebSocketComm- Parameters:
attachment- The attachment object for the web socket.
isCompressionSupported
public boolean isCompressionSupported()Flag for supporting software compression on client side.- Specified by:
isCompressionSupportedin interfaceIWebSocketComm- Returns:
- The support flag depending on the subProtocol chosen.