public interface WebSocket
Modifier and Type | Method and Description |
---|---|
void |
close()
Convenience function which behaves like close(CloseFrame.NORMAL)
|
void |
close(int code)
sends the closing handshake. may be send in response to an other handshake.
|
void |
close(int code,
String message)
sends the closing handshake. may be send in response to an other handshake.
|
void |
closeConnection(int code,
String message)
This will close the connection immediately without a proper close handshake.
|
<T> T |
getAttachment()
Getter for the connection attachment.
|
Draft |
getDraft()
Getter for the draft
|
InetSocketAddress |
getLocalSocketAddress()
Returns the address of the endpoint this socket is bound to, or
null if it is not
bound. |
IProtocol |
getProtocol()
Returns the used Sec-WebSocket-Protocol for this websocket connection
|
ReadyState |
getReadyState()
Retrieve the WebSocket 'ReadyState'.
|
InetSocketAddress |
getRemoteSocketAddress()
Returns the address of the endpoint this socket is connected to, or
null if it is
unconnected. |
String |
getResourceDescriptor()
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. |
SSLSession |
getSSLSession()
Returns the ssl session of websocket, if ssl/wss is used for this instance.
|
boolean |
hasBufferedData()
Checks if the websocket has buffered data
|
boolean |
hasSSLSupport()
Does this websocket use an encrypted (wss/ssl) or unencrypted (ws) connection
|
boolean |
isClosed()
Is the websocket in the state CLOSED
|
boolean |
isClosing()
Is the websocket in the state CLOSING
|
boolean |
isFlushAndClose()
Returns true when no further frames may be submitted
This happens before the socket connection is closed. |
boolean |
isOpen()
Is the websocket in the state OPEN
|
void |
send(byte[] bytes)
Send Binary data (plain bytes) to the other end.
|
void |
send(ByteBuffer bytes)
Send Binary data (plain bytes) to the other end.
|
void |
send(String text)
Send Text data to the other end.
|
void |
sendFragmentedFrame(Opcode op,
ByteBuffer buffer,
boolean fin)
Allows to send continuous/fragmented frames conveniently.
|
void |
sendFrame(Collection<Framedata> frames)
Send a collection of frames to the other end
|
void |
sendFrame(Framedata framedata)
Send a frame to the other end
|
void |
sendPing()
Send a ping to the other end
|
<T> void |
setAttachment(T attachment)
Setter for an attachment on the socket connection.
|
void close(int code, String message)
code
- the closing codemessage
- the closing messagevoid close(int code)
code
- the closing codevoid close()
void closeConnection(int code, String message)
code
- the closing codemessage
- the closing messagevoid send(String text)
text
- the text data to sendWebsocketNotConnectedException
- websocket is not yet connectedvoid send(ByteBuffer bytes)
bytes
- the binary data to sendIllegalArgumentException
- the data is nullWebsocketNotConnectedException
- websocket is not yet connectedvoid send(byte[] bytes)
bytes
- the byte array to sendIllegalArgumentException
- the data is nullWebsocketNotConnectedException
- websocket is not yet connectedvoid sendFrame(Framedata framedata)
framedata
- the frame to send to the other endvoid sendFrame(Collection<Framedata> frames)
frames
- the frames to send to the other endvoid sendPing()
WebsocketNotConnectedException
- websocket is not yet connectedvoid sendFragmentedFrame(Opcode op, ByteBuffer buffer, boolean fin)
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.
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.boolean hasBufferedData()
InetSocketAddress getRemoteSocketAddress()
null
if it is
unconnected.InetSocketAddress getLocalSocketAddress()
null
if it is not
bound.boolean isOpen()
boolean isClosing()
boolean isFlushAndClose()
boolean isClosed()
Draft getDraft()
ReadyState getReadyState()
String getResourceDescriptor()
<T> void setAttachment(T attachment)
T
- The type of the attachmentattachment
- The object to be attached to the user<T> T getAttachment()
T
- The type of the attachmentboolean hasSSLSupport()
SSLSession getSSLSession() throws IllegalArgumentException
IllegalArgumentException
- the underlying channel does not use ssl (use hasSSLSupport()
to check)IProtocol getProtocol()
IllegalArgumentException
- the underlying draft does not support a Sec-WebSocket-ProtocolCopyright © 2022. All rights reserved.