public interface WebSocketBase extends ReadStream<Buffer>, WriteStream<Buffer>
Represents an HTML 5 Websocket<p>
Instances of this class are created and provided to the handler of an
HttpClient
when a successful websocket connect attempt occurs.<p>
On the server side, the subclass ServerWebSocket
is used instead.<p>
It implements both ReadStream
and WriteStream
so it can be used with
Pump
to pump data with flow control.<p>
Instances of this class are not thread-safe<p>
Modifier and Type | Method and Description |
---|---|
String |
binaryHandlerID()
When a
Websocket is created it automatically registers an event handler with the eventbus, the ID of that
handler is given by binaryHandlerID .<p>
Given this ID, a different event loop can send a binary frame to that event handler using the event bus and
that buffer will be received by this instance in its own event loop and written to the underlying connection. |
void |
close()
Close the websocket
|
WebSocketBase |
closeHandler(Handler<Void> handler)
Set a closed handler on the connection
|
WebSocketBase |
drainHandler(Handler<Void> handler)
Set a drain handler on the stream.
|
WebSocketBase |
endHandler(Handler<Void> endHandler)
Set an end handler.
|
WebSocketBase |
exceptionHandler(Handler<Throwable> handler)
Set an exception handler.
|
WebSocketBase |
frameHandler(Handler<WebSocketFrame> handler)
Set a frame handler on the connection
|
WebSocketBase |
handler(Handler<Buffer> handler)
Set a data handler.
|
SocketAddress |
localAddress()
Return the local address for this socket
|
WebSocketBase |
pause()
Pause the
ReadSupport . |
SocketAddress |
remoteAddress()
Return the remote address for this socket
|
WebSocketBase |
resume()
Resume reading.
|
WebSocketBase |
setWriteQueueMaxSize(int maxSize)
Set the maximum size of the write queue to
maxSize . |
String |
textHandlerID()
When a
Websocket is created it automatically registers an event handler with the eventbus, the ID of that
handler is given by textHandlerID .<p>
Given this ID, a different event loop can send a text frame to that event handler using the event bus and
that buffer will be received by this instance in its own event loop and written to the underlying connection. |
WebSocketBase |
write(Buffer data)
Write some data to the stream.
|
WebSocketBase |
writeFrame(WebSocketFrame frame) |
WebSocketBase |
writeMessage(Buffer data)
Writes a (potentially large) piece of data as a websocket message - this may be split into multiple frames
if it is large.
|
writeQueueFull
WebSocketBase exceptionHandler(Handler<Throwable> handler)
StreamBase
Set an exception handler.
exceptionHandler
in interface ReadStream<Buffer>
exceptionHandler
in interface StreamBase
exceptionHandler
in interface WriteStream<Buffer>
WebSocketBase handler(Handler<Buffer> handler)
ReadStream
Set a data handler. As data is read, the handler will be called with the data.
handler
in interface ReadStream<Buffer>
WebSocketBase pause()
ReadStream
Pause the ReadSupport
. While it’s paused, no data will be sent to the dataHandler
pause
in interface ReadStream<Buffer>
WebSocketBase resume()
ReadStream
Resume reading. If the ReadSupport
has been paused, reading will recommence on it.
resume
in interface ReadStream<Buffer>
WebSocketBase endHandler(Handler<Void> endHandler)
ReadStream
Set an end handler. Once the stream has ended, and there is no more data to be read, this handler will be called.
endHandler
in interface ReadStream<Buffer>
WebSocketBase write(Buffer data)
WriteStream
Write some data to the stream. The data is put on an internal write queue, and the write actually happens
asynchronously. To avoid running out of memory by putting too much on the write queue,
check the WriteStream.writeQueueFull()
method before writing. This is done automatically if using a Pump
.
write
in interface WriteStream<Buffer>
WebSocketBase setWriteQueueMaxSize(int maxSize)
WriteStream
Set the maximum size of the write queue to maxSize
. You will still be able to write to the stream even
if there is more than maxSize
bytes in the write queue. This is used as an indicator by classes such as
Pump
to provide flow control.
setWriteQueueMaxSize
in interface WriteStream<Buffer>
WebSocketBase drainHandler(Handler<Void> handler)
WriteStream
Set a drain handler on the stream. If the write queue is full, then the handler will be called when the write
queue has been reduced to maxSize / 2. See Pump
for an example of this being used.
drainHandler
in interface WriteStream<Buffer>
String binaryHandlerID()
When a Websocket
is created it automatically registers an event handler with the eventbus, the ID of that
handler is given by binaryHandlerID
.<p>
Given this ID, a different event loop can send a binary frame to that event handler using the event bus and
that buffer will be received by this instance in its own event loop and written to the underlying connection. This
allows you to write data to other websockets which are owned by different event loops.
String textHandlerID()
When a Websocket
is created it automatically registers an event handler with the eventbus, the ID of that
handler is given by textHandlerID
.<p>
Given this ID, a different event loop can send a text frame to that event handler using the event bus and
that buffer will be received by this instance in its own event loop and written to the underlying connection. This
allows you to write data to other websockets which are owned by different event loops.
WebSocketBase writeFrame(WebSocketFrame frame)
WebSocketBase writeMessage(Buffer data)
Writes a (potentially large) piece of data as a websocket message - this may be split into multiple frames if it is large.
WebSocketBase closeHandler(Handler<Void> handler)
Set a closed handler on the connection
WebSocketBase frameHandler(Handler<WebSocketFrame> handler)
Set a frame handler on the connection
void close()
Close the websocket
SocketAddress remoteAddress()
Return the remote address for this socket
SocketAddress localAddress()
Return the local address for this socket
Copyright © 2014. All Rights Reserved.