public class WebSocketImpl extends java.lang.Object implements WebSocket
WebSocket.READYSTATE, WebSocket.Role| Modifier and Type | Field and Description |
|---|---|
java.nio.channels.ByteChannel |
channel
the possibly wrapped channel object whose selection is controlled by
key |
static boolean |
DEBUG |
static java.util.List<Draft> |
defaultdraftlist |
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| Constructor and Description |
|---|
WebSocketImpl(WebSocketListener listener,
Draft draft)
crates a websocket with client role
|
WebSocketImpl(WebSocketListener listener,
Draft draft,
java.net.Socket socket)
Deprecated.
|
WebSocketImpl(WebSocketListener listener,
java.util.List<Draft> drafts)
crates a websocket with server role
|
WebSocketImpl(WebSocketListener listener,
java.util.List<Draft> drafts,
java.net.Socket socket)
Deprecated.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Convenience function which behaves like close(CloseFrame.NORMAL)
|
void |
close(int code) |
void |
close(int code,
java.lang.String message)
sends the closing handshake.
|
void |
close(InvalidDataException e) |
void |
closeConnection() |
protected void |
closeConnection(int code,
boolean remote) |
void |
closeConnection(int code,
java.lang.String message)
This will close the connection immediately without a proper close handshake.
|
protected void |
closeConnection(int code,
java.lang.String message,
boolean remote) |
void |
decode(java.nio.ByteBuffer socketBuffer) |
void |
eot() |
protected void |
flushAndClose(int code,
java.lang.String message,
boolean remote) |
Draft |
getDraft() |
java.net.InetSocketAddress |
getLocalSocketAddress() |
WebSocket.READYSTATE |
getReadyState()
Retrieve the WebSocket 'readyState'.
|
java.net.InetSocketAddress |
getRemoteSocketAddress() |
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() |
int |
hashCode() |
boolean |
isClosed()
Returns whether the close handshake has been completed and the socket is closed.
|
boolean |
isClosing() |
boolean |
isConnecting() |
boolean |
isFlushAndClose()
Returns true when no further frames may be submitted
This happens before the socket connection is closed. |
boolean |
isOpen() |
void |
send(byte[] bytes) |
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) |
void |
startHandshake(ClientHandshakeBuilder handshakedata) |
java.lang.String |
toString() |
public static int RCVBUF
public static boolean DEBUG
public static final java.util.List<Draft> defaultdraftlist
public java.nio.channels.SelectionKey key
public java.nio.channels.ByteChannel channel
keypublic final java.util.concurrent.BlockingQueue<java.nio.ByteBuffer> outQueue
public final java.util.concurrent.BlockingQueue<java.nio.ByteBuffer> inQueue
public volatile WebSocketServer.WebSocketWorker workerThread
public WebSocketImpl(WebSocketListener listener, java.util.List<Draft> drafts)
public WebSocketImpl(WebSocketListener listener, Draft draft)
listener - may be unbound@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)
public void close(int code,
java.lang.String message)
WebSocketprotected void closeConnection(int code,
java.lang.String message,
boolean remote)
remote - Indicates who "generated" code.true means that this endpoint received the code from the other endpoint.remote may also be true if this endpoint started the closing handshake since the other endpoint may not simply echo the code but close the connection the same time this endpoint does do but with an other code. protected void closeConnection(int code,
boolean remote)
public void closeConnection()
public void closeConnection(int code,
java.lang.String message)
WebSocketcloseConnection in interface WebSocketprotected void flushAndClose(int code,
java.lang.String message,
boolean remote)
public void eot()
public void close(InvalidDataException e)
public void send(java.lang.String text)
throws WebsocketNotConnectedException
send in interface WebSocketjava.lang.IllegalArgumentExceptionjava.nio.channels.NotYetConnectedExceptionWebsocketNotConnectedExceptionpublic void send(java.nio.ByteBuffer bytes)
throws java.lang.IllegalArgumentException,
WebsocketNotConnectedException
send in interface WebSocketjava.lang.IllegalArgumentExceptionjava.nio.channels.NotYetConnectedExceptionWebsocketNotConnectedExceptionpublic void send(byte[] bytes)
throws java.lang.IllegalArgumentException,
WebsocketNotConnectedException
send in interface WebSocketjava.lang.IllegalArgumentExceptionWebsocketNotConnectedExceptionpublic void sendFragmentedFrame(Framedata.Opcode op, java.nio.ByteBuffer buffer, boolean fin)
WebSocketsendFragmentedFrame in interface 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 boolean hasBufferedData()
hasBufferedData in interface WebSocketpublic void startHandshake(ClientHandshakeBuilder handshakedata) throws InvalidHandshakeException
InvalidHandshakeExceptionpublic boolean isConnecting()
isConnecting in interface WebSocketpublic boolean isFlushAndClose()
WebSocketisFlushAndClose in interface WebSocketpublic boolean isClosed()
WebSocketpublic WebSocket.READYSTATE getReadyState()
WebSocketgetReadyState in interface WebSocketpublic int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Objectpublic java.net.InetSocketAddress getRemoteSocketAddress()
getRemoteSocketAddress in interface WebSocketpublic java.net.InetSocketAddress getLocalSocketAddress()
getLocalSocketAddress in interface WebSocketpublic void close()
WebSocketpublic java.lang.String getResourceDescriptor()
WebSocketgetResourceDescriptor in interface WebSocket