public interface WebSocketBase extends ReadStream<Buffer>, WriteStream<Buffer>
It implements both ReadStream and WriteStream so it can be used with
Pump to pump data with flow control.
| Modifier and Type | Method and Description |
|---|---|
String |
binaryHandlerID()
When a
Websocket is created it automatically registers an event handler with the event bus - the ID of that
handler is given by this method. |
WebSocketBase |
binaryMessageHandler(Handler<Buffer> handler)
Set a binary message handler on the connection.
|
void |
close()
Close the WebSocket sending the default close frame.
|
void |
close(short statusCode) |
void |
close(short statusCode,
String reason) |
WebSocketBase |
closeHandler(Handler<Void> handler)
Set a close handler.
|
WebSocketBase |
drainHandler(Handler<Void> handler)
Set a drain handler on the stream.
|
void |
end()
Calls
close() |
WebSocketBase |
endHandler(Handler<Void> endHandler)
Set an end handler.
|
WebSocketBase |
exceptionHandler(Handler<Throwable> handler)
Set an exception handler on the read stream.
|
WebSocketBase |
fetch(long amount)
Fetch the specified
amount of elements. |
WebSocketBase |
frameHandler(Handler<WebSocketFrame> handler)
Set a frame handler on the connection.
|
WebSocketBase |
handler(Handler<Buffer> handler)
Set a data handler.
|
boolean |
isSsl() |
SocketAddress |
localAddress() |
WebSocketBase |
pause()
Pause the
ReadStream, it sets the buffer in fetch mode and clears the actual demand. |
X509Certificate[] |
peerCertificateChain()
Note: Java SE 5+ recommends to use javax.net.ssl.SSLSession#getPeerCertificates() instead of
of javax.net.ssl.SSLSession#getPeerCertificateChain() which this method is based on.
|
WebSocketBase |
pongHandler(Handler<Buffer> handler)
Set a pong message handler on the connection.
|
SocketAddress |
remoteAddress() |
WebSocketBase |
resume()
Resume reading, and sets the buffer in
flowing mode. |
WebSocketBase |
setWriteQueueMaxSize(int maxSize)
Set the maximum size of the write queue to
maxSize. |
SSLSession |
sslSession() |
String |
subProtocol()
Returns the websocket sub protocol selected by the websocket handshake.
|
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. |
WebSocketBase |
textMessageHandler(Handler<String> handler)
Set a text message handler on the connection.
|
WebSocketBase |
write(Buffer data)
Write some data to the stream.
|
WebSocketBase |
writeBinaryMessage(Buffer data)
Writes a (potentially large) piece of binary data to the connection.
|
WebSocketBase |
writeFinalBinaryFrame(Buffer data)
Write a final WebSocket binary frame to the connection
|
WebSocketBase |
writeFinalTextFrame(String text)
Write a final WebSocket text frame to the connection
|
WebSocketBase |
writeFrame(WebSocketFrame frame)
Write a WebSocket frame to the connection
|
WebSocketBase |
writePing(Buffer data)
Writes a ping to the connection.
|
WebSocketBase |
writePong(Buffer data)
Writes a pong to the connection.
|
WebSocketBase |
writeTextMessage(String text)
Writes a (potentially large) piece of text data to the connection.
|
end, writeQueueFullWebSocketBase exceptionHandler(Handler<Throwable> handler)
ReadStreamexceptionHandler in interface ReadStream<Buffer>exceptionHandler in interface StreamBaseexceptionHandler in interface WriteStream<Buffer>handler - the exception handlerWebSocketBase handler(Handler<Buffer> handler)
ReadStreamhandler in interface ReadStream<Buffer>WebSocketBase pause()
ReadStreamReadStream, it sets the buffer in fetch mode and clears the actual demand.
While it's paused, no data will be sent to the data handler.
pause in interface ReadStream<Buffer>WebSocketBase resume()
ReadStreamflowing mode.
If the ReadStream has been paused, reading will recommence on it.resume in interface ReadStream<Buffer>WebSocketBase fetch(long amount)
ReadStreamamount of elements. If the ReadStream has been paused, reading will
recommence with the specified amount of items, otherwise the specified amount will
be added to the current stream demand.fetch in interface ReadStream<Buffer>WebSocketBase endHandler(Handler<Void> endHandler)
ReadStreamendHandler in interface ReadStream<Buffer>WebSocketBase write(Buffer data)
WriteStreamWriteStream.writeQueueFull() method before writing. This is done automatically if using a Pump.write in interface WriteStream<Buffer>data - the data to writeWebSocketBase setWriteQueueMaxSize(int maxSize)
WriteStreammaxSize. You will still be able to write to the stream even
if there is more than maxSize items in the write queue. This is used as an indicator by classes such as
Pump to provide flow control.
The value is defined by the implementation of the stream, e.g in bytes for a
NetSocket, the number of Message for a
MessageProducer, etc...setWriteQueueMaxSize in interface WriteStream<Buffer>maxSize - the max size of the write streamWebSocketBase drainHandler(Handler<Void> handler)
WriteStreamPump for an example of this being used.
The stream implementation defines when the drain handler, for example it could be when the queue size has been
reduced to maxSize / 2.drainHandler in interface WriteStream<Buffer>handler - the handlerString binaryHandlerID()
Websocket is created it automatically registers an event handler with the event bus - the ID of that
handler is given by this method.
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()
Websocket is created it automatically registers an event handler with the eventbus, the ID of that
handler is given by textHandlerID.
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.
String subProtocol()
null when the handler receives the websocket callback as the
handshake will not be completed yet.WebSocketBase writeFrame(WebSocketFrame frame)
frame - the frame to writeWebSocketBase writeFinalTextFrame(String text)
text - The text to writeWebSocketBase writeFinalBinaryFrame(Buffer data)
data - The data to writeWebSocketBase writeBinaryMessage(Buffer data)
data - the data to writeWebSocketBase writeTextMessage(String text)
text - the data to writeWebSocketBase writePing(Buffer data)
This method should not be used to write application data and should only be used for implementing a keep alive or to ensure the client is still responsive, see RFC 6455 Section 5.5.2.
There is no pingHandler because RFC 6455 section 5.5.2 clearly states that the only response to a ping is a pong with identical contents.
data - the data to write, may be at most 125 bytesWebSocketBase writePong(Buffer data)
This method should not be used to write application data and should only be used for implementing a keep alive or to ensure the client is still responsive, see RFC 6455 Section 5.5.2.
There is no need to manually write a Pong, as the server and client both handle responding to a ping with a pong automatically and this is exposed to users.RFC 6455 Section 5.5.3 states that pongs may be sent unsolicited in order to implement a one way heartbeat.
data - the data to write, may be at most 125 bytesWebSocketBase closeHandler(Handler<Void> handler)
handler - the handlerWebSocketBase frameHandler(Handler<WebSocketFrame> handler)
handler - the handlerWebSocketBase textMessageHandler(Handler<String> handler)
binaryMessageHandler(Handler), but the buffer will be converted to a String firsthandler - the handlerWebSocketBase binaryMessageHandler(Handler<Buffer> handler)
handler(Handler)
except that if a message comes into the socket in multiple frames, the data from the frames will be aggregated
into a single buffer before calling the handler (using WebSocketFrame.isFinal() to find the boundaries).handler - the handlerWebSocketBase pongHandler(Handler<Buffer> handler)
Pong frames may be at most 125 bytes (octets).
There is no ping handler since pings should immediately be responded to with a pong with identical content
Pong frames may be received unsolicited.
handler - the handlervoid end()
close()end in interface WriteStream<Buffer>void close()
void close(short statusCode)
void close(short statusCode,
String reason)
SocketAddress remoteAddress()
SocketAddress localAddress()
boolean isSsl()
HttpConnection is encrypted via SSL/TLS.SSLSession sslSession()
SSLSessionX509Certificate[] peerCertificateChain() throws SSLPeerUnverifiedException
sslSession() to
access that method.SSLPeerUnverifiedException - SSL peer's identity has not been verified.SSLSession.getPeerCertificateChain(),
sslSession()Copyright © 2018 Eclipse. All rights reserved.