public class WebSocketImpl extends java.lang.Object implements WebSocket
WebSocket.READYSTATE, WebSocket.Role| 限定符和类型 | 字段和说明 |
|---|---|
java.nio.channels.ByteChannel |
channel
the possibly wrapped channel object whose selection is controlled by
key |
static boolean |
DEBUG
Activate debug mode for additional infos
|
java.util.concurrent.BlockingQueue<java.nio.ByteBuffer> |
inQueue
Queue of buffers that need to be processed
|
java.nio.channels.SelectionKey |
key |
java.util.concurrent.BlockingQueue<java.nio.ByteBuffer> |
outQueue
Queue of buffers that need to be sent to the client.
|
static int |
RCVBUF |
WebSocketServer.WebSocketWorker |
workerThread
Helper variable meant to store the thread which ( exclusively ) triggers this objects decode method.
|
DEFAULT_PORT, DEFAULT_WSS_PORT| 构造器和说明 |
|---|
WebSocketImpl(WebSocketListener listener,
Draft draft)
creates a websocket with client role
|
WebSocketImpl(WebSocketListener listener,
Draft draft,
java.net.Socket socket)
已过时。
|
WebSocketImpl(WebSocketListener listener,
java.util.List<Draft> drafts)
Creates a websocket with server role
|
WebSocketImpl(WebSocketListener listener,
java.util.List<Draft> drafts,
java.net.Socket socket)
已过时。
|
| 限定符和类型 | 方法和说明 |
|---|---|
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 |
close(InvalidDataException e) |
void |
closeConnection() |
void |
closeConnection(int code,
java.lang.String message)
This will close the connection immediately without a proper close handshake.
|
void |
decode(java.nio.ByteBuffer socketBuffer)
Method to decode the provided ByteBuffer
|
void |
eot() |
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
|
int |
hashCode() |
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
|
void |
startHandshake(ClientHandshakeBuilder handshakedata) |
java.lang.String |
toString() |
public static int RCVBUF
public static boolean DEBUG
public final java.util.concurrent.BlockingQueue<java.nio.ByteBuffer> outQueue
public final java.util.concurrent.BlockingQueue<java.nio.ByteBuffer> inQueue
public java.nio.channels.SelectionKey key
public java.nio.channels.ByteChannel channel
keypublic volatile WebSocketServer.WebSocketWorker workerThread
public WebSocketImpl(WebSocketListener listener, java.util.List<Draft> drafts)
listener - The listener for this instancedrafts - The drafts which should be usedpublic WebSocketImpl(WebSocketListener listener, Draft draft)
listener - The listener for this instancedraft - The draft which should be used@Deprecated public WebSocketImpl(WebSocketListener listener, Draft draft, java.net.Socket socket)
@Deprecated public WebSocketImpl(WebSocketListener listener, java.util.List<Draft> drafts, java.net.Socket socket)
public void decode(java.nio.ByteBuffer socketBuffer)
socketBuffer - the ByteBuffer to decodepublic void close(int code,
java.lang.String message)
WebSocketpublic void closeConnection()
public void closeConnection(int code,
java.lang.String message)
WebSocketcloseConnection 在接口中 WebSocketcode - the closing codemessage - the closing messagepublic void eot()
public void close(int code)
WebSocketpublic void close(InvalidDataException e)
public void send(java.lang.String text)
throws WebsocketNotConnectedException
send 在接口中 WebSockettext - the text data to sendjava.nio.channels.NotYetConnectedException - websocket is not yet connectedWebsocketNotConnectedExceptionpublic void send(java.nio.ByteBuffer bytes)
throws java.lang.IllegalArgumentException,
WebsocketNotConnectedException
send 在接口中 WebSocketbytes - the binary data to sendjava.lang.IllegalArgumentException - the data is nulljava.nio.channels.NotYetConnectedException - websocket is not yet connectedWebsocketNotConnectedExceptionpublic void send(byte[] bytes)
throws java.lang.IllegalArgumentException,
WebsocketNotConnectedException
WebSocketsend 在接口中 WebSocketbytes - the byte array to sendjava.lang.IllegalArgumentException - the data is nullWebsocketNotConnectedExceptionpublic void sendFragmentedFrame(Framedata.Opcode op, java.nio.ByteBuffer buffer, boolean fin)
WebSocketsendFragmentedFrame 在接口中 WebSocketop - 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.public void sendFrame(Framedata framedata)
WebSocketpublic void sendPing()
throws java.nio.channels.NotYetConnectedException
WebSocketpublic boolean hasBufferedData()
WebSockethasBufferedData 在接口中 WebSocketpublic void startHandshake(ClientHandshakeBuilder handshakedata) throws InvalidHandshakeException
public boolean isConnecting()
WebSocketisConnecting 在接口中 WebSocketpublic boolean isOpen()
WebSocketpublic boolean isClosing()
WebSocketpublic boolean isFlushAndClose()
WebSocketisFlushAndClose 在接口中 WebSocketpublic boolean isClosed()
WebSocketpublic WebSocket.READYSTATE getReadyState()
WebSocketgetReadyState 在接口中 WebSocketpublic int hashCode()
hashCode 在类中 java.lang.Objectpublic java.lang.String toString()
toString 在类中 java.lang.Objectpublic java.net.InetSocketAddress getRemoteSocketAddress()
WebSocketnull if it is unconnected.getRemoteSocketAddress 在接口中 WebSocketpublic java.net.InetSocketAddress getLocalSocketAddress()
WebSocketgetLocalSocketAddress 在接口中 WebSocketpublic void close()
WebSocketpublic java.lang.String getResourceDescriptor()
WebSocketgetResourceDescriptor 在接口中 WebSocket