Package org.java_websocket.client
Class WebSocketClient
- java.lang.Object
-
- org.java_websocket.WebSocketAdapter
-
- org.java_websocket.AbstractWebSocket
-
- org.java_websocket.client.WebSocketClient
-
- All Implemented Interfaces:
java.lang.Runnable,WebSocket,WebSocketListener
public abstract class WebSocketClient extends AbstractWebSocket implements java.lang.Runnable, WebSocket
A subclass must implement at least onOpen, onClose, and onMessage to be useful. At runtime the user is expected to establish a connection viaconnect(), then receive events likeonMessage(String)via the overloaded methods and tosend(String)data to the server.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classWebSocketClient.WebsocketWriteThread
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.CountDownLatchcloseLatchThe latch for closeBlocking()private java.util.concurrent.CountDownLatchconnectLatchThe latch for connectBlocking()private java.lang.ThreadconnectReadThreadThe thread to connect and read messageprivate intconnectTimeoutThe socket timeout value to be used in milliseconds.private DnsResolverdnsResolverDNS resolver that translates a URI to an InetAddressprivate DraftdraftThe draft to useprivate WebSocketImplengineThe underlying engineprivate java.util.Map<java.lang.String,java.lang.String>headersThe additional headers to useprivate java.io.OutputStreamostreamThe used OutputStreamprivate java.net.ProxyproxyThe used proxy, if anyprivate java.net.SocketsocketThe socket for this WebSocketClientprivate javax.net.SocketFactorysocketFactoryThe SocketFactory for this WebSocketClientprotected java.net.URIuriThe URI this channel is supposed to connect to.private java.lang.ThreadwriteThreadThe thread to write outgoing message
-
Constructor Summary
Constructors Constructor Description WebSocketClient(java.net.URI serverUri)Constructs a WebSocketClient instance and sets it to the connect to the specified URI.WebSocketClient(java.net.URI serverUri, java.util.Map<java.lang.String,java.lang.String> httpHeaders)Constructs a WebSocketClient instance and sets it to the connect to the specified URI.WebSocketClient(java.net.URI serverUri, Draft protocolDraft)Constructs a WebSocketClient instance and sets it to the connect to the specified URI.WebSocketClient(java.net.URI serverUri, Draft protocolDraft, java.util.Map<java.lang.String,java.lang.String> httpHeaders)Constructs a WebSocketClient instance and sets it to the connect to the specified URI.WebSocketClient(java.net.URI serverUri, Draft protocolDraft, java.util.Map<java.lang.String,java.lang.String> httpHeaders, int connectTimeout)Constructs a WebSocketClient instance and sets it to the connect to the specified URI.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddHeader(java.lang.String key, java.lang.String value)voidclearHeaders()voidclose()Initiates the websocket close handshake.voidclose(int code)sends the closing handshake.voidclose(int code, java.lang.String message)sends the closing handshake.voidcloseBlocking()Same asclosebut blocks until the websocket closed or failed to do so.voidcloseConnection(int code, java.lang.String message)This will close the connection immediately without a proper close handshake.voidconnect()Initiates the websocket connection.booleanconnectBlocking()Same asconnectbut blocks until the websocket connected or failed to do so.booleanconnectBlocking(long timeout, java.util.concurrent.TimeUnit timeUnit)Same asconnectbut blocks with a timeout until the websocket connected or failed to do so.<T> TgetAttachment()Getter for the connection attachment.WebSocketgetConnection()Getter for the engineprotected java.util.Collection<WebSocket>getConnections()Getter to get all the currently available connectionsDraftgetDraft()Returns the protocol version this channel uses.
For more infos see https://github.com/TooTallNate/Java-WebSocket/wiki/Draftsjava.net.InetSocketAddressgetLocalSocketAddress()Returns the address of the endpoint this socket is bound to, ornullif it is not bound.java.net.InetSocketAddressgetLocalSocketAddress(WebSocket conn)private intgetPort()Extract the specified portIProtocolgetProtocol()Returns the used Sec-WebSocket-Protocol for this websocket connectionReadyStategetReadyState()This represents the state of the connection.java.net.InetSocketAddressgetRemoteSocketAddress()Returns the address of the endpoint this socket is connected to, ornullif it is unconnected.java.net.InetSocketAddressgetRemoteSocketAddress(WebSocket conn)java.lang.StringgetResourceDescriptor()Returns the HTTP Request-URI as defined by http://tools.ietf.org/html/rfc2616#section-5.1.2
If the opening handshake has not yet happened it will return null.java.net.SocketgetSocket()Returns the socket to allow Hostname Verificationjavax.net.ssl.SSLSessiongetSSLSession()Returns the ssl session of websocket, if ssl/wss is used for this instance.java.net.URIgetURI()Returns the URI that this WebSocketClient is connected to.private voidhandleIOException(java.io.IOException e)Method to give some additional info for specific IOExceptionsbooleanhasBufferedData()Checks if the websocket has buffered databooleanhasSSLSupport()Does this websocket use an encrypted (wss/ssl) or unencrypted (ws) connectionbooleanisClosed()Is the websocket in the state CLOSEDbooleanisClosing()Is the websocket in the state CLOSINGbooleanisFlushAndClose()Returns true when no further frames may be submitted
This happens before the socket connection is closed.booleanisOpen()Is the websocket in the state OPENabstract voidonClose(int code, java.lang.String reason, boolean remote)Called after the websocket connection has been closed.voidonCloseInitiated(int code, java.lang.String reason)Send when this peer sends a close handshakevoidonClosing(int code, java.lang.String reason, boolean remote)Called as soon as no further frames are acceptedabstract voidonError(java.lang.Exception ex)Called when errors occurs.abstract voidonMessage(java.lang.String message)Callback for string messages received from the remote hostvoidonMessage(java.nio.ByteBuffer bytes)Callback for binary messages received from the remote hostabstract voidonOpen(ServerHandshake handshakedata)Called after an opening handshake has been performed and the given websocket is ready to be written on.protected voidonSetSSLParameters(javax.net.ssl.SSLParameters sslParameters)Apply specific SSLParameters If you override this method make sure to always call super.onSetSSLParameters() to ensure the hostname validation is activevoidonWebsocketClose(WebSocket conn, int code, java.lang.String reason, boolean remote)Calls subclass' implementation of onClose.voidonWebsocketCloseInitiated(WebSocket conn, int code, java.lang.String reason)send when this peer sends a close handshakevoidonWebsocketClosing(WebSocket conn, int code, java.lang.String reason, boolean remote)Called as soon as no further frames are acceptedvoidonWebsocketError(WebSocket conn, java.lang.Exception ex)Calls subclass' implementation of onIOError.voidonWebsocketMessage(WebSocket conn, java.lang.String message)Calls subclass' implementation of onMessage.voidonWebsocketMessage(WebSocket conn, java.nio.ByteBuffer blob)Called when an entire binary frame has been received.voidonWebsocketOpen(WebSocket conn, Handshakedata handshake)Calls subclass' implementation of onOpen.voidonWriteDemand(WebSocket conn)This method is used to inform the selector thread that there is data queued to be written to the socket.private booleanprepareSocket()voidreconnect()Reinitiates the websocket connection.booleanreconnectBlocking()Same asreconnectbut blocks until the websocket reconnected or failed to do so.java.lang.StringremoveHeader(java.lang.String key)private voidreset()Reset everything relevant to allow a reconnectvoidrun()voidsend(byte[] data)Sends binary data to the connected webSocket server.voidsend(java.lang.String text)Sends text to the connected websocket server.voidsend(java.nio.ByteBuffer bytes)Send Binary data (plain bytes) to the other end.voidsendFragmentedFrame(Opcode op, java.nio.ByteBuffer buffer, boolean fin)Allows to send continuous/fragmented frames conveniently.voidsendFrame(java.util.Collection<Framedata> frames)Send a collection of frames to the other endvoidsendFrame(Framedata framedata)Send a frame to the other endprivate voidsendHandshake()Create and send the handshake to the other endpointvoidsendPing()Send a ping to the other end<T> voidsetAttachment(T attachment)Setter for an attachment on the socket connection.voidsetDnsResolver(DnsResolver dnsResolver)Sets a custom DNS resolver.voidsetProxy(java.net.Proxy proxy)Method to set a proxy for this connectionvoidsetSocket(java.net.Socket socket)Deprecated.use setSocketFactoryvoidsetSocketFactory(javax.net.SocketFactory socketFactory)Accepts a SocketFactory.
This method must be called beforeconnect.private voidupgradeSocketToSSL()-
Methods inherited from class org.java_websocket.AbstractWebSocket
getConnectionLostTimeout, isReuseAddr, isTcpNoDelay, setConnectionLostTimeout, setReuseAddr, setTcpNoDelay, startConnectionLostTimer, stopConnectionLostTimer
-
Methods inherited from class org.java_websocket.WebSocketAdapter
onPreparePing, onWebsocketHandshakeReceivedAsClient, onWebsocketHandshakeReceivedAsServer, onWebsocketHandshakeSentAsClient, onWebsocketPing, onWebsocketPong
-
-
-
-
Field Detail
-
uri
protected java.net.URI uri
The URI this channel is supposed to connect to.
-
engine
private WebSocketImpl engine
The underlying engine
-
socket
private java.net.Socket socket
The socket for this WebSocketClient
-
socketFactory
private javax.net.SocketFactory socketFactory
The SocketFactory for this WebSocketClient- Since:
- 1.4.0
-
ostream
private java.io.OutputStream ostream
The used OutputStream
-
proxy
private java.net.Proxy proxy
The used proxy, if any
-
writeThread
private java.lang.Thread writeThread
The thread to write outgoing message
-
connectReadThread
private java.lang.Thread connectReadThread
The thread to connect and read message
-
draft
private Draft draft
The draft to use
-
headers
private java.util.Map<java.lang.String,java.lang.String> headers
The additional headers to use
-
connectLatch
private java.util.concurrent.CountDownLatch connectLatch
The latch for connectBlocking()
-
closeLatch
private java.util.concurrent.CountDownLatch closeLatch
The latch for closeBlocking()
-
connectTimeout
private int connectTimeout
The socket timeout value to be used in milliseconds.
-
dnsResolver
private DnsResolver dnsResolver
DNS resolver that translates a URI to an InetAddress- Since:
- 1.4.1
- See Also:
InetAddress
-
-
Constructor Detail
-
WebSocketClient
public WebSocketClient(java.net.URI serverUri)
Constructs a WebSocketClient instance and sets it to the connect to the specified URI. The channel does not attampt to connect automatically. The connection will be established once you call connect.- Parameters:
serverUri- the server URI to connect to
-
WebSocketClient
public WebSocketClient(java.net.URI serverUri, Draft protocolDraft)Constructs a WebSocketClient instance and sets it to the connect to the specified URI. The channel does not attampt to connect automatically. The connection will be established once you call connect.- Parameters:
serverUri- the server URI to connect toprotocolDraft- The draft which should be used for this connection
-
WebSocketClient
public WebSocketClient(java.net.URI serverUri, java.util.Map<java.lang.String,java.lang.String> httpHeaders)Constructs a WebSocketClient instance and sets it to the connect to the specified URI. The channel does not attampt to connect automatically. The connection will be established once you call connect.- Parameters:
serverUri- the server URI to connect tohttpHeaders- Additional HTTP-Headers- Since:
- 1.3.8
-
WebSocketClient
public WebSocketClient(java.net.URI serverUri, Draft protocolDraft, java.util.Map<java.lang.String,java.lang.String> httpHeaders)Constructs a WebSocketClient instance and sets it to the connect to the specified URI. The channel does not attampt to connect automatically. The connection will be established once you call connect.- Parameters:
serverUri- the server URI to connect toprotocolDraft- The draft which should be used for this connectionhttpHeaders- Additional HTTP-Headers- Since:
- 1.3.8
-
WebSocketClient
public WebSocketClient(java.net.URI serverUri, Draft protocolDraft, java.util.Map<java.lang.String,java.lang.String> httpHeaders, int connectTimeout)Constructs a WebSocketClient instance and sets it to the connect to the specified URI. The channel does not attampt to connect automatically. The connection will be established once you call connect.- Parameters:
serverUri- the server URI to connect toprotocolDraft- The draft which should be used for this connectionhttpHeaders- Additional HTTP-HeadersconnectTimeout- The Timeout for the connection
-
-
Method Detail
-
getURI
public java.net.URI getURI()
Returns the URI that this WebSocketClient is connected to.- Returns:
- the URI connected to
-
getDraft
public Draft getDraft()
Returns the protocol version this channel uses.
For more infos see https://github.com/TooTallNate/Java-WebSocket/wiki/Drafts
-
getSocket
public java.net.Socket getSocket()
Returns the socket to allow Hostname Verification- Returns:
- the socket used for this connection
-
addHeader
public void addHeader(java.lang.String key, java.lang.String value)- Parameters:
key- Name of the header to add.value- Value of the header to add.- Since:
- 1.4.1 Adds an additional header to be sent in the handshake.
If the connection is already made, adding headers has no effect, unless reconnect is called, which then a new handshake is sent.
If a header with the same key already exists, it is overridden.
-
removeHeader
public java.lang.String removeHeader(java.lang.String key)
- Parameters:
key- Name of the header to remove.- Returns:
- the previous value associated with key, or null if there was no mapping for key.
- Since:
- 1.4.1 Removes a header from the handshake to be sent, if header key exists.
-
clearHeaders
public void clearHeaders()
- Since:
- 1.4.1 Clears all previously put headers.
-
setDnsResolver
public void setDnsResolver(DnsResolver dnsResolver)
Sets a custom DNS resolver.- Parameters:
dnsResolver- The DnsResolver to use.- Since:
- 1.4.1
-
reconnect
public void reconnect()
Reinitiates the websocket connection. This method does not block.- Since:
- 1.3.8
-
reconnectBlocking
public boolean reconnectBlocking() throws java.lang.InterruptedExceptionSame asreconnectbut blocks until the websocket reconnected or failed to do so.- Returns:
- Returns whether it succeeded or not.
- Throws:
java.lang.InterruptedException- Thrown when the threads get interrupted- Since:
- 1.3.8
-
reset
private void reset()
Reset everything relevant to allow a reconnect- Since:
- 1.3.8
-
connect
public void connect()
Initiates the websocket connection. This method does not block.
-
connectBlocking
public boolean connectBlocking() throws java.lang.InterruptedExceptionSame asconnectbut blocks until the websocket connected or failed to do so.- Returns:
- Returns whether it succeeded or not.
- Throws:
java.lang.InterruptedException- Thrown when the threads get interrupted
-
connectBlocking
public boolean connectBlocking(long timeout, java.util.concurrent.TimeUnit timeUnit) throws java.lang.InterruptedExceptionSame asconnectbut blocks with a timeout until the websocket connected or failed to do so.- Parameters:
timeout- The connect timeouttimeUnit- The timeout time unit- Returns:
- Returns whether it succeeded or not.
- Throws:
java.lang.InterruptedException- Thrown when the threads get interrupted
-
close
public void close()
Initiates the websocket close handshake. This method does not block
In oder to make sure the connection is closed usecloseBlocking
-
closeBlocking
public void closeBlocking() throws java.lang.InterruptedExceptionSame asclosebut blocks until the websocket closed or failed to do so.- Throws:
java.lang.InterruptedException- Thrown when the threads get interrupted
-
send
public void send(java.lang.String text)
Sends text to the connected websocket server.
-
send
public void send(byte[] data)
Sends binary data to the connected webSocket server.
-
getAttachment
public <T> T getAttachment()
Description copied from interface:WebSocketGetter for the connection attachment.- Specified by:
getAttachmentin interfaceWebSocket- Type Parameters:
T- The type of the attachment- Returns:
- Returns the user attachment
-
setAttachment
public <T> void setAttachment(T attachment)
Description copied from interface:WebSocketSetter for an attachment on the socket connection. The attachment may be of any type.- Specified by:
setAttachmentin interfaceWebSocket- Type Parameters:
T- The type of the attachment- Parameters:
attachment- The object to be attached to the user
-
getConnections
protected java.util.Collection<WebSocket> getConnections()
Description copied from class:AbstractWebSocketGetter to get all the currently available connections- Specified by:
getConnectionsin classAbstractWebSocket- Returns:
- the currently available connections
-
sendPing
public void sendPing()
Description copied from interface:WebSocketSend a ping to the other end
-
run
public void run()
- Specified by:
runin interfacejava.lang.Runnable
-
upgradeSocketToSSL
private void upgradeSocketToSSL() throws java.security.NoSuchAlgorithmException, java.security.KeyManagementException, java.io.IOException- Throws:
java.security.NoSuchAlgorithmExceptionjava.security.KeyManagementExceptionjava.io.IOException
-
prepareSocket
private boolean prepareSocket() throws java.io.IOException- Throws:
java.io.IOException
-
onSetSSLParameters
protected void onSetSSLParameters(javax.net.ssl.SSLParameters sslParameters)
Apply specific SSLParameters If you override this method make sure to always call super.onSetSSLParameters() to ensure the hostname validation is active- Parameters:
sslParameters- the SSLParameters which will be used for the SSLSocket
-
getPort
private int getPort()
Extract the specified port- Returns:
- the specified port or the default port for the specific scheme
-
sendHandshake
private void sendHandshake() throws InvalidHandshakeExceptionCreate and send the handshake to the other endpoint- Throws:
InvalidHandshakeException- a invalid handshake was created
-
getReadyState
public ReadyState getReadyState()
This represents the state of the connection.- Specified by:
getReadyStatein interfaceWebSocket- Returns:
- Returns '0 = CONNECTING', '1 = OPEN', '2 = CLOSING' or '3 = CLOSED'
-
onWebsocketMessage
public final void onWebsocketMessage(WebSocket conn, java.lang.String message)
Calls subclass' implementation of onMessage.- Specified by:
onWebsocketMessagein interfaceWebSocketListener- Parameters:
conn- The WebSocket instance this event is occurring on.message- The UTF-8 decoded message that was received.
-
onWebsocketMessage
public final void onWebsocketMessage(WebSocket conn, java.nio.ByteBuffer blob)
Description copied from interface:WebSocketListenerCalled when an entire binary frame has been received. Do whatever you want here...- Specified by:
onWebsocketMessagein interfaceWebSocketListener- Parameters:
conn- The WebSocket instance this event is occurring on.blob- The binary message that was received.
-
onWebsocketOpen
public final void onWebsocketOpen(WebSocket conn, Handshakedata handshake)
Calls subclass' implementation of onOpen.- Specified by:
onWebsocketOpenin interfaceWebSocketListener- Parameters:
conn- The WebSocket instance this event is occurring on.handshake- The handshake of the websocket instance
-
onWebsocketClose
public final void onWebsocketClose(WebSocket conn, int code, java.lang.String reason, boolean remote)
Calls subclass' implementation of onClose.- Specified by:
onWebsocketClosein interfaceWebSocketListener- Parameters:
conn- The WebSocket instance this event is occurring on.code- The codes can be looked up here:CloseFramereason- Additional information stringremote- Returns whether or not the closing of the connection was initiated by the remote host.
-
onWebsocketError
public final void onWebsocketError(WebSocket conn, java.lang.Exception ex)
Calls subclass' implementation of onIOError.- Specified by:
onWebsocketErrorin interfaceWebSocketListener- Parameters:
conn- The WebSocket instance this event is occurring on.ex- The exception that occurred.
Might be null if the exception is not related to any specific connection. For example if the server port could not be bound.
-
onWriteDemand
public final void onWriteDemand(WebSocket conn)
Description copied from interface:WebSocketListenerThis method is used to inform the selector thread that there is data queued to be written to the socket.- Specified by:
onWriteDemandin interfaceWebSocketListener- Parameters:
conn- The WebSocket instance this event is occurring on.
-
onWebsocketCloseInitiated
public void onWebsocketCloseInitiated(WebSocket conn, int code, java.lang.String reason)
Description copied from interface:WebSocketListenersend when this peer sends a close handshake- Specified by:
onWebsocketCloseInitiatedin interfaceWebSocketListener- Parameters:
conn- The WebSocket instance this event is occurring on.code- The codes can be looked up here:CloseFramereason- Additional information string
-
onWebsocketClosing
public void onWebsocketClosing(WebSocket conn, int code, java.lang.String reason, boolean remote)
Description copied from interface:WebSocketListenerCalled as soon as no further frames are accepted- Specified by:
onWebsocketClosingin interfaceWebSocketListener- Parameters:
conn- The WebSocket instance this event is occurring on.code- The codes can be looked up here:CloseFramereason- Additional information stringremote- Returns whether or not the closing of the connection was initiated by the remote host.
-
onCloseInitiated
public void onCloseInitiated(int code, java.lang.String reason)Send when this peer sends a close handshake- Parameters:
code- The codes can be looked up here:CloseFramereason- Additional information string
-
onClosing
public void onClosing(int code, java.lang.String reason, boolean remote)Called as soon as no further frames are accepted- Parameters:
code- The codes can be looked up here:CloseFramereason- Additional information stringremote- Returns whether or not the closing of the connection was initiated by the remote host.
-
getConnection
public WebSocket getConnection()
Getter for the engine- Returns:
- the engine
-
getLocalSocketAddress
public java.net.InetSocketAddress getLocalSocketAddress(WebSocket conn)
- Specified by:
getLocalSocketAddressin interfaceWebSocketListener- Parameters:
conn- The WebSocket instance this event is occurring on.- Returns:
- Returns the address of the endpoint this socket is bound to.
- See Also:
WebSocket.getLocalSocketAddress()
-
getRemoteSocketAddress
public java.net.InetSocketAddress getRemoteSocketAddress(WebSocket conn)
- Specified by:
getRemoteSocketAddressin interfaceWebSocketListener- Parameters:
conn- The WebSocket instance this event is occurring on.- Returns:
- Returns the address of the endpoint this socket is connected to, or
nullif it is unconnected. - See Also:
WebSocket.getRemoteSocketAddress()
-
onOpen
public abstract void onOpen(ServerHandshake handshakedata)
Called after an opening handshake has been performed and the given websocket is ready to be written on.- Parameters:
handshakedata- The handshake of the websocket instance
-
onMessage
public abstract void onMessage(java.lang.String message)
Callback for string messages received from the remote host- Parameters:
message- The UTF-8 decoded message that was received.- See Also:
onMessage(ByteBuffer)
-
onClose
public abstract void onClose(int code, java.lang.String reason, boolean remote)Called after the websocket connection has been closed.- Parameters:
code- The codes can be looked up here:CloseFramereason- Additional information stringremote- Returns whether or not the closing of the connection was initiated by the remote host.
-
onError
public abstract void onError(java.lang.Exception ex)
Called when errors occurs. If an error causes the websocket connection to failonClose(int, String, boolean)will be called additionally.
This method will be called primarily because of IO or protocol errors.
If the given exception is an RuntimeException that probably means that you encountered a bug.- Parameters:
ex- The exception causing this error
-
onMessage
public void onMessage(java.nio.ByteBuffer bytes)
Callback for binary messages received from the remote host- Parameters:
bytes- The binary message that was received.- See Also:
onMessage(String)
-
setProxy
public void setProxy(java.net.Proxy proxy)
Method to set a proxy for this connection- Parameters:
proxy- the proxy to use for this websocket client
-
setSocket
@Deprecated public void setSocket(java.net.Socket socket)
Deprecated.use setSocketFactoryAccepts bound and unbound sockets.
This method must be called beforeconnect. If the given socket is not yet bound it will be bound to the uri specified in the constructor.- Parameters:
socket- The socket which should be used for the connection
-
setSocketFactory
public void setSocketFactory(javax.net.SocketFactory socketFactory)
Accepts a SocketFactory.
This method must be called beforeconnect. The socket will be bound to the uri specified in the constructor.- Parameters:
socketFactory- The socket factory which should be used for the connection.
-
sendFragmentedFrame
public void sendFragmentedFrame(Opcode op, java.nio.ByteBuffer buffer, boolean fin)
Description copied from interface:WebSocketAllows to send continuous/fragmented frames conveniently.
For more into on this frame type see http://tools.ietf.org/html/rfc6455#section-5.4
If the first frame you send is also the last then it is not a fragmented frame and will received via onMessage instead of onFragmented even though it was send by this method.
- Specified by:
sendFragmentedFramein interfaceWebSocket- Parameters:
op- This is only important for the first frame in the sequence. Opcode.TEXT, Opcode.BINARY are allowed.buffer- The buffer which contains the payload. It may have no bytes remaining.fin- true means the current frame is the last in the sequence.
-
isOpen
public boolean isOpen()
Description copied from interface:WebSocketIs the websocket in the state OPEN
-
isFlushAndClose
public boolean isFlushAndClose()
Description copied from interface:WebSocketReturns true when no further frames may be submitted
This happens before the socket connection is closed.- Specified by:
isFlushAndClosein interfaceWebSocket- Returns:
- true when no further frames may be submitted
-
isClosed
public boolean isClosed()
Description copied from interface:WebSocketIs the websocket in the state CLOSED
-
isClosing
public boolean isClosing()
Description copied from interface:WebSocketIs the websocket in the state CLOSING
-
hasBufferedData
public boolean hasBufferedData()
Description copied from interface:WebSocketChecks if the websocket has buffered data- Specified by:
hasBufferedDatain interfaceWebSocket- Returns:
- has the websocket buffered data
-
close
public void close(int code)
Description copied from interface:WebSocketsends the closing handshake. may be send in response to an other handshake.
-
close
public void close(int code, java.lang.String message)Description copied from interface:WebSocketsends the closing handshake. may be send in response to an other handshake.
-
closeConnection
public void closeConnection(int code, java.lang.String message)Description copied from interface:WebSocketThis will close the connection immediately without a proper close handshake. The code and the message therefore won't be transferred over the wire also they will be forwarded to onClose/onWebsocketClose.- Specified by:
closeConnectionin interfaceWebSocket- Parameters:
code- the closing codemessage- the closing message
-
send
public void send(java.nio.ByteBuffer bytes)
Description copied from interface:WebSocketSend Binary data (plain bytes) to the other end.
-
sendFrame
public void sendFrame(Framedata framedata)
Description copied from interface:WebSocketSend a frame to the other end
-
sendFrame
public void sendFrame(java.util.Collection<Framedata> frames)
Description copied from interface:WebSocketSend a collection of frames to the other end
-
getLocalSocketAddress
public java.net.InetSocketAddress getLocalSocketAddress()
Description copied from interface:WebSocketReturns the address of the endpoint this socket is bound to, ornullif it is not bound.- Specified by:
getLocalSocketAddressin interfaceWebSocket- Returns:
- the local socket address or null, if this socket is not bound
-
getRemoteSocketAddress
public java.net.InetSocketAddress getRemoteSocketAddress()
Description copied from interface:WebSocketReturns the address of the endpoint this socket is connected to, ornullif it is unconnected.- Specified by:
getRemoteSocketAddressin interfaceWebSocket- Returns:
- the remote socket address or null, if this socket is unconnected
-
getResourceDescriptor
public java.lang.String getResourceDescriptor()
Description copied from interface:WebSocketReturns the HTTP Request-URI as defined by http://tools.ietf.org/html/rfc2616#section-5.1.2
If the opening handshake has not yet happened it will return null.- Specified by:
getResourceDescriptorin interfaceWebSocket- Returns:
- Returns the decoded path component of this URI.
-
hasSSLSupport
public boolean hasSSLSupport()
Description copied from interface:WebSocketDoes this websocket use an encrypted (wss/ssl) or unencrypted (ws) connection- Specified by:
hasSSLSupportin interfaceWebSocket- Returns:
- true, if the websocket does use wss and therefore has a SSLSession
-
getSSLSession
public javax.net.ssl.SSLSession getSSLSession()
Description copied from interface:WebSocketReturns the ssl session of websocket, if ssl/wss is used for this instance.- Specified by:
getSSLSessionin interfaceWebSocket- Returns:
- the ssl session of this websocket instance
-
getProtocol
public IProtocol getProtocol()
Description copied from interface:WebSocketReturns the used Sec-WebSocket-Protocol for this websocket connection- Specified by:
getProtocolin interfaceWebSocket- Returns:
- the Sec-WebSocket-Protocol or null, if no draft available
-
handleIOException
private void handleIOException(java.io.IOException e)
Method to give some additional info for specific IOExceptions- Parameters:
e- the IOException causing a eot.
-
-