public interface WebSocket
| 限定符和类型 | 字段和说明 |
|---|---|
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.
|
| 限定符和类型 | 方法和说明 |
|---|---|
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.
|
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 |
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.
|
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)
text - the text data to sendNotYetConnectedException - websocket is not yet connectedvoid send(ByteBuffer bytes)
bytes - the binary data to sendIllegalArgumentException - the data is nullNotYetConnectedException - websocket is not yet connectedvoid send(byte[] bytes)
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(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()
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 attachmentCopyright © 2020. All rights reserved.