public interface WebSocket
限定符和类型 | 接口和说明 |
---|---|
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
|
限定符和类型 | 字段和说明 |
---|---|
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.
|
void |
close(int code,
java.lang.String message)
sends the closing handshake.
|
void |
closeConnection(int code,
java.lang.String message)
This will close the connection immediately without a proper close handshake.
|
Draft |
getDraft()
Getter for the draft
|
java.net.InetSocketAddress |
getLocalSocketAddress()
Returns the address of the endpoint this socket is bound to.
|
WebSocket.READYSTATE |
getReadyState()
Retrieve the WebSocket 'readyState'.
|
java.net.InetSocketAddress |
getRemoteSocketAddress()
Returns the address of the endpoint this socket is connected to, or
null if it is unconnected. |
java.lang.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()
Is the websocket in the state CONNECTING
|
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(java.nio.ByteBuffer bytes)
Send Binary data (plain bytes) to the other end.
|
void |
send(java.lang.String text)
Send Text data to the other end.
|
void |
sendFragmentedFrame(Framedata.Opcode op,
java.nio.ByteBuffer buffer,
boolean fin)
Allows to send continuous/fragmented frames conveniently.
|
void |
sendFrame(Framedata framedata)
Send a frame to the other end
|
void |
sendPing()
Send a ping to the other end
|
static final int DEFAULT_PORT
static final int DEFAULT_WSS_PORT
void close(int code, java.lang.String message)
code
- the closing codemessage
- the closing messagevoid close(int code)
code
- the closing codevoid close()
void closeConnection(int code, java.lang.String message)
code
- the closing codemessage
- the closing messagevoid send(java.lang.String text) throws java.nio.channels.NotYetConnectedException
text
- the text data to sendjava.nio.channels.NotYetConnectedException
- websocket is not yet connectedvoid send(java.nio.ByteBuffer bytes) throws java.lang.IllegalArgumentException, java.nio.channels.NotYetConnectedException
bytes
- the binary data to sendjava.lang.IllegalArgumentException
- the data is nulljava.nio.channels.NotYetConnectedException
- websocket is not yet connectedvoid send(byte[] bytes) throws java.lang.IllegalArgumentException, java.nio.channels.NotYetConnectedException
bytes
- the byte array to sendjava.lang.IllegalArgumentException
- the data is nulljava.nio.channels.NotYetConnectedException
- websocket is not yet connectedvoid sendFrame(Framedata framedata)
framedata
- the frame to send to the other endvoid sendPing() throws java.nio.channels.NotYetConnectedException
java.nio.channels.NotYetConnectedException
- websocket is not yet connectedvoid sendFragmentedFrame(Framedata.Opcode op, java.nio.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()
java.net.InetSocketAddress getRemoteSocketAddress()
null
if it is unconnected.java.net.InetSocketAddress getLocalSocketAddress()
boolean isConnecting()
boolean isOpen()
boolean isClosing()
boolean isFlushAndClose()
boolean isClosed()
Draft getDraft()
WebSocket.READYSTATE getReadyState()
java.lang.String getResourceDescriptor()