public class WebSocketImpl extends Object implements WebSocket
| 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.
|
BlockingQueue<ByteBuffer> |
inQueue
Queue of buffers that need to be processed
|
BlockingQueue<ByteBuffer> |
outQueue
Queue of buffers that need to be sent to the client.
|
static int |
RCVBUF
Initial buffer size
|
| Constructor and Description |
|---|
WebSocketImpl(WebSocketListener listener,
Draft draft)
creates a websocket with client role
|
WebSocketImpl(WebSocketListener listener,
List<Draft> drafts)
Creates a websocket with server role
|
| Modifier and Type | Method and Description |
|---|---|
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 |
close(int code,
String message,
boolean remote) |
void |
close(InvalidDataException e) |
void |
closeConnection() |
protected void |
closeConnection(int code,
boolean remote) |
void |
closeConnection(int code,
String message)
This will close the connection immediately without a proper close handshake.
|
void |
closeConnection(int code,
String message,
boolean remote)
This will close the connection immediately without a proper close handshake.
|
void |
decode(ByteBuffer socketBuffer)
Method to decode the provided ByteBuffer
|
void |
eot() |
void |
flushAndClose(int code,
String message,
boolean remote) |
<T> T |
getAttachment()
Getter for the connection attachment.
|
ByteChannel |
getChannel() |
Draft |
getDraft()
Getter for the draft
|
InetSocketAddress |
getLocalSocketAddress()
Returns the address of the endpoint this socket is bound to, or
null if it is not
bound. |
IProtocol |
getProtocol()
Returns the used Sec-WebSocket-Protocol for this websocket connection
|
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. |
SelectionKey |
getSelectionKey() |
SSLSession |
getSSLSession()
Returns the ssl session of websocket, if ssl/wss is used for this instance.
|
WebSocketListener |
getWebSocketListener()
Getter for the websocket listener
|
WebSocketServer.WebSocketWorker |
getWorkerThread() |
boolean |
hasBufferedData()
Checks if the websocket has buffered data
|
boolean |
hasSSLSupport()
Does this websocket use an encrypted (wss/ssl) or unencrypted (ws) connection
|
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.
|
void |
setChannel(ByteChannel channel) |
void |
setSelectionKey(SelectionKey key) |
void |
setWorkerThread(WebSocketServer.WebSocketWorker workerThread) |
void |
startHandshake(ClientHandshakeBuilder handshakedata) |
String |
toString() |
void |
updateLastPong()
Update the timestamp when the last pong was received
|
public static final int DEFAULT_PORT
public static final int DEFAULT_WSS_PORT
public static final int RCVBUF
public final BlockingQueue<ByteBuffer> outQueue
public final BlockingQueue<ByteBuffer> inQueue
public WebSocketImpl(WebSocketListener listener, 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 usedpublic void decode(ByteBuffer socketBuffer)
socketBuffer - the ByteBuffer to decodepublic void close(int code,
String message,
boolean remote)
public void close(int code,
String message)
WebSocketpublic void closeConnection(int code,
String message,
boolean remote)
code - the closing codemessage - the closing messageremote - 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,
String message)
WebSocketcloseConnection in interface WebSocketcode - the closing codemessage - the closing messagepublic void flushAndClose(int code,
String message,
boolean remote)
public void eot()
public void close(int code)
WebSocketpublic void close(InvalidDataException e)
public void send(String text)
send in interface WebSockettext - the text data to sendWebsocketNotConnectedException - websocket is not yet connectedpublic void send(ByteBuffer bytes)
send in interface WebSocketbytes - the binary data to sendIllegalArgumentException - the data is nullWebsocketNotConnectedException - websocket is not yet connectedpublic void send(byte[] bytes)
WebSocketpublic void sendFragmentedFrame(Opcode op, ByteBuffer buffer, boolean fin)
WebSocketIf 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.
sendFragmentedFrame 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 void sendFrame(Collection<Framedata> frames)
WebSocketpublic void sendFrame(Framedata framedata)
WebSocketpublic void sendPing()
throws NullPointerException
WebSocketsendPing in interface WebSocketNullPointerExceptionpublic boolean hasBufferedData()
WebSockethasBufferedData in interface WebSocketpublic void startHandshake(ClientHandshakeBuilder handshakedata) throws InvalidHandshakeException
InvalidHandshakeExceptionpublic boolean isOpen()
WebSocketpublic boolean isClosing()
WebSocketpublic boolean isFlushAndClose()
WebSocketisFlushAndClose in interface WebSocketpublic boolean isClosed()
WebSocketpublic ReadyState getReadyState()
WebSocketgetReadyState in interface WebSocketpublic void setSelectionKey(SelectionKey key)
key - the selection key of this implementationpublic SelectionKey getSelectionKey()
public InetSocketAddress getRemoteSocketAddress()
WebSocketnull if it is
unconnected.getRemoteSocketAddress in interface WebSocketpublic InetSocketAddress getLocalSocketAddress()
WebSocketnull if it is not
bound.getLocalSocketAddress in interface WebSocketpublic void close()
WebSocketpublic String getResourceDescriptor()
WebSocketgetResourceDescriptor in interface WebSocketpublic void updateLastPong()
public WebSocketListener getWebSocketListener()
public <T> T getAttachment()
WebSocketgetAttachment in interface WebSocketT - The type of the attachmentpublic boolean hasSSLSupport()
WebSockethasSSLSupport in interface WebSocketpublic SSLSession getSSLSession()
WebSocketgetSSLSession in interface WebSocketpublic IProtocol getProtocol()
WebSocketgetProtocol in interface WebSocketpublic <T> void setAttachment(T attachment)
WebSocketsetAttachment in interface WebSocketT - The type of the attachmentattachment - The object to be attached to the userpublic ByteChannel getChannel()
public void setChannel(ByteChannel channel)
public WebSocketServer.WebSocketWorker getWorkerThread()
public void setWorkerThread(WebSocketServer.WebSocketWorker workerThread)
Copyright © 2021. All rights reserved.