public class WebSocketSession extends Object implements WebSocketConnection, IncomingFrames, OutgoingFrames
BaseConnection.State, BaseConnection.SuspendToken
Constructor and Description |
---|
WebSocketSession(EventDriver websocket,
BaseConnection connection,
WebSocketPolicy policy,
String subprotocol) |
Modifier and Type | Method and Description |
---|---|
void |
close()
Send a websocket Close frame,
StatusCode.NORMAL , without a reason. |
void |
close(int statusCode,
String reason)
Send a websocket Close frame, with status code.
|
void |
disconnect()
Terminate the connection (no close frame sent)
|
IncomingFrames |
getIncoming() |
OutgoingFrames |
getOutgoing() |
WebSocketPolicy |
getPolicy()
Access the (now read-only)
WebSocketPolicy in use for this connection. |
InetSocketAddress |
getRemoteAddress()
Get the remote Address in use for this connection.
|
BaseConnection.State |
getState()
Get the state of the connection.
|
String |
getSubProtocol()
Get the SubProtocol in use for this connection.
|
void |
incoming(WebSocketException e) |
void |
incoming(WebSocketFrame frame) |
boolean |
isOpen()
Simple test to see if connection is open (and not closed)
|
boolean |
isReading()
Tests if the connection is actively reading.
|
void |
notifyClosing()
Notify that the connection has entered the closing handshake
|
void |
onConnect() |
<C> void |
output(C context,
Callback<C> callback,
WebSocketFrame frame) |
<C> void |
ping(C context,
Callback<C> callback,
byte[] payload)
Send a single ping messages.
|
void |
setOutgoing(OutgoingFrames outgoing) |
BaseConnection.SuspendToken |
suspend()
Suspend a the incoming read events on the connection.
|
String |
toString() |
<C> void |
write(C context,
Callback<C> callback,
byte[] buf,
int offset,
int len)
Send a a binary message.
|
<C> void |
write(C context,
Callback<C> callback,
ByteBuffer buffer)
Send a a binary message.
|
<C> void |
write(C context,
Callback<C> callback,
String message)
Send a series of text messages.
|
public WebSocketSession(EventDriver websocket, BaseConnection connection, WebSocketPolicy policy, String subprotocol)
public void close()
BaseConnection
StatusCode.NORMAL
, without a reason.
Basic usage: results in an non-blocking async write, then connection close.
close
in interface BaseConnection
StatusCode
,
BaseConnection.close(int, String)
public void close(int statusCode, String reason)
BaseConnection
Advanced usage: results in an non-blocking async write, then connection close.
close
in interface BaseConnection
statusCode
- the status codereason
- the (optional) reason. (can be null for no reason)StatusCode
public void disconnect()
BaseConnection
disconnect
in interface BaseConnection
public IncomingFrames getIncoming()
public OutgoingFrames getOutgoing()
public WebSocketPolicy getPolicy()
WebSocketConnection
WebSocketPolicy
in use for this connection.getPolicy
in interface WebSocketConnection
public InetSocketAddress getRemoteAddress()
BaseConnection
getRemoteAddress
in interface BaseConnection
public BaseConnection.State getState()
BaseConnection
getState
in interface BaseConnection
public String getSubProtocol()
WebSocketConnection
getSubProtocol
in interface WebSocketConnection
public void incoming(WebSocketException e)
incoming
in interface IncomingFrames
public void incoming(WebSocketFrame frame)
incoming
in interface IncomingFrames
public boolean isOpen()
BaseConnection
isOpen
in interface BaseConnection
public boolean isReading()
BaseConnection
isReading
in interface BaseConnection
public void notifyClosing()
BaseConnection
notifyClosing
in interface BaseConnection
public void onConnect()
public <C> void output(C context, Callback<C> callback, WebSocketFrame frame) throws IOException
output
in interface OutgoingFrames
IOException
public <C> void ping(C context, Callback<C> callback, byte[] payload) throws IOException
NIO style with callbacks, allows for knowledge of successful ping send.
Use @OnWebSocketFrame and monitor Pong frames
ping
in interface WebSocketConnection
IOException
public void setOutgoing(OutgoingFrames outgoing)
public BaseConnection.SuspendToken suspend()
BaseConnection
suspend
in interface BaseConnection
public <C> void write(C context, Callback<C> callback, byte[] buf, int offset, int len) throws IOException
NIO style with callbacks, allows for concurrent results of the write operation.
write
in interface WebSocketConnection
IOException
public <C> void write(C context, Callback<C> callback, ByteBuffer buffer) throws IOException
NIO style with callbacks, allows for concurrent results of the write operation.
write
in interface WebSocketConnection
IOException
public <C> void write(C context, Callback<C> callback, String message) throws IOException
NIO style with callbacks, allows for concurrent results of the entire write operation. (Callback is only called once at the end of processing all of the messages)
write
in interface WebSocketConnection
IOException
Copyright © 1995-2012 Mort Bay Consulting. All Rights Reserved.