public interface WebSocket
Modifier and Type | Interface and Description |
---|---|
static class |
WebSocket.READYSTATE
Enum which represents the state a websocket may be in
|
static class |
WebSocket.Role
Enum which represents the states a websocket may be in
|
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_PORT
The default port of WebSockets, as defined in the spec.
|
static int |
DEFAULT_WSS_PORT
The default wss port of WebSockets, as defined in the spec.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Convenience function which behaves like close(CloseFrame.NORMAL)
|
void |
close(int code)
sends the closing handshake.
|
void |
close(int code,
String message)
sends the closing 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.
|
WebSocket.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. |
boolean |
hasBufferedData()
Checks if the websocket has buffered data
|
boolean |
isClosed()
Is the websocket in the state CLOSED
|
boolean |
isClosing()
Is the websocket in the state CLOSING
|
boolean |
isConnecting()
Deprecated.
|
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(Framedata.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.
|
static final int DEFAULT_PORT
static final int DEFAULT_WSS_PORT
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) throws NotYetConnectedException
text
- the text data to sendNotYetConnectedException
- websocket is not yet connectedvoid send(ByteBuffer bytes) throws IllegalArgumentException, NotYetConnectedException
bytes
- the binary data to sendIllegalArgumentException
- the data is nullNotYetConnectedException
- websocket is not yet connectedvoid send(byte[] bytes) throws IllegalArgumentException, NotYetConnectedException
bytes
- the byte array to sendIllegalArgumentException
- the data is nullNotYetConnectedException
- 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() throws NotYetConnectedException
NotYetConnectedException
- websocket is not yet connectedvoid sendFragmentedFrame(Framedata.Opcode op, ByteBuffer buffer, boolean fin)
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()
@Deprecated boolean isConnecting()
boolean isOpen()
boolean isClosing()
boolean isFlushAndClose()
boolean isClosed()
Draft getDraft()
WebSocket.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 attachmentCopyright © 2018. All rights reserved.