public class WebSocketImpl extends Object implements WebSocket
WebSocket.READYSTATE, WebSocket.Role
Modifier and Type | Field and Description |
---|---|
ByteChannel |
channel
the possibly wrapped channel object whose selection is controlled by
key |
static boolean |
DEBUG
Activate debug mode for additional infos
|
BlockingQueue<ByteBuffer> |
inQueue
Queue of buffers that need to be processed
|
SelectionKey |
key |
BlockingQueue<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)
creates a websocket with client role
|
WebSocketImpl(WebSocketListener listener,
Draft draft,
Socket socket)
Deprecated.
|
WebSocketImpl(WebSocketListener listener,
List<Draft> drafts)
Creates a websocket with server role
|
WebSocketImpl(WebSocketListener listener,
List<Draft> drafts,
Socket socket)
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Convenience function which behaves like close(CloseFrame.NORMAL)
|
void |
close(int code)
sends the closing handshake.
|
void |
close(int code,
String message)
sends the closing 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.
|
Draft |
getDraft()
Getter for the draft
|
InetSocketAddress |
getLocalSocketAddress()
Returns the address of the endpoint this socket is bound to.
|
WebSocket.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. |
WebSocketListener |
getWebSocketListener()
Getter for the websocket listener
|
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()
Deprecated.
|
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(Framedata.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 |
startHandshake(ClientHandshakeBuilder handshakedata) |
String |
toString() |
void |
updateLastPong()
Update the timestamp when the last pong was received
|
public static int RCVBUF
public static boolean DEBUG
public final BlockingQueue<ByteBuffer> outQueue
public final BlockingQueue<ByteBuffer> inQueue
public SelectionKey key
public ByteChannel channel
key
public volatile WebSocketServer.WebSocketWorker workerThread
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 used@Deprecated public WebSocketImpl(WebSocketListener listener, Draft draft, Socket socket)
@Deprecated public WebSocketImpl(WebSocketListener listener, List<Draft> drafts, Socket socket)
public void decode(ByteBuffer socketBuffer)
socketBuffer
- the ByteBuffer to decodepublic void close(int code, String message, boolean remote)
public void close(int code, String message)
WebSocket
public 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)
WebSocket
closeConnection
in interface WebSocket
code
- the closing codemessage
- the closing messagepublic void flushAndClose(int code, String message, boolean remote)
public void eot()
public void close(int code)
WebSocket
public void close(InvalidDataException e)
public void send(String text) throws WebsocketNotConnectedException
send
in interface WebSocket
text
- the text data to sendNotYetConnectedException
- websocket is not yet connectedWebsocketNotConnectedException
public void send(ByteBuffer bytes) throws IllegalArgumentException, WebsocketNotConnectedException
send
in interface WebSocket
bytes
- the binary data to sendIllegalArgumentException
- the data is nullNotYetConnectedException
- websocket is not yet connectedWebsocketNotConnectedException
public void send(byte[] bytes) throws IllegalArgumentException, WebsocketNotConnectedException
WebSocket
send
in interface WebSocket
bytes
- the byte array to sendIllegalArgumentException
- the data is nullWebsocketNotConnectedException
public void sendFragmentedFrame(Framedata.Opcode op, ByteBuffer buffer, boolean fin)
WebSocket
sendFragmentedFrame
in interface WebSocket
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.public void sendFrame(Collection<Framedata> frames)
WebSocket
public void sendFrame(Framedata framedata)
WebSocket
public void sendPing() throws NotYetConnectedException
WebSocket
sendPing
in interface WebSocket
NotYetConnectedException
- websocket is not yet connectedpublic boolean hasBufferedData()
WebSocket
hasBufferedData
in interface WebSocket
public void startHandshake(ClientHandshakeBuilder handshakedata) throws InvalidHandshakeException
InvalidHandshakeException
@Deprecated public boolean isConnecting()
WebSocket
isConnecting
in interface WebSocket
public boolean isOpen()
WebSocket
public boolean isClosing()
WebSocket
public boolean isFlushAndClose()
WebSocket
isFlushAndClose
in interface WebSocket
public boolean isClosed()
WebSocket
public WebSocket.READYSTATE getReadyState()
WebSocket
getReadyState
in interface WebSocket
public InetSocketAddress getRemoteSocketAddress()
WebSocket
null
if it is unconnected.getRemoteSocketAddress
in interface WebSocket
public InetSocketAddress getLocalSocketAddress()
WebSocket
getLocalSocketAddress
in interface WebSocket
public void close()
WebSocket
public String getResourceDescriptor()
WebSocket
getResourceDescriptor
in interface WebSocket
public void updateLastPong()
public WebSocketListener getWebSocketListener()
public <T> T getAttachment()
WebSocket
getAttachment
in interface WebSocket
T
- The type of the attachmentpublic <T> void setAttachment(T attachment)
WebSocket
setAttachment
in interface WebSocket
T
- The type of the attachmentattachment
- The object to be attached to the userCopyright © 2018. All rights reserved.