public class ServerWebSocket extends Object implements WebSocketBase
Instances of this class are passed into a HttpServer.websocketHandler(io.vertx.core.Handler<io.vertx.reactivex.core.http.ServerWebSocket>) or provided
when a WebSocket handshake is manually HttpServerRequest.upgrade()ed.
original non RX-ified interface using Vert.x codegen.| Modifier and Type | Field and Description |
|---|---|
static <any> |
__TYPE_ARG |
| Constructor and Description |
|---|
ServerWebSocket(ServerWebSocket delegate) |
| Modifier and Type | Method and Description |
|---|---|
void |
accept()
Accept the WebSocket and terminate the WebSocket handshake.
|
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) |
ServerWebSocket |
closeHandler(Handler<Void> handler)
Set a close handler.
|
ServerWebSocket |
drainHandler(Handler<Void> handler)
Set a drain handler on the stream.
|
void |
end()
Calls
WebSocketBase.close() |
void |
end(Buffer t)
Same as
WebSocketBase.end(io.vertx.reactivex.core.buffer.Buffer) but writes some data to the stream before ending. |
ServerWebSocket |
endHandler(Handler<Void> endHandler)
Set an end handler.
|
boolean |
equals(Object o) |
ServerWebSocket |
exceptionHandler(Handler<Throwable> handler)
Set an exception handler on the read stream.
|
ServerWebSocket |
fetch(long amount)
Fetch the specified
amount of elements. |
ServerWebSocket |
frameHandler(Handler<WebSocketFrame> handler)
Set a frame handler on the connection.
|
ServerWebSocket |
getDelegate() |
ServerWebSocket |
handler(Handler<Buffer> handler)
Set a data handler.
|
int |
hashCode() |
MultiMap |
headers() |
boolean |
isSsl() |
SocketAddress |
localAddress() |
static ServerWebSocket |
newInstance(ServerWebSocket arg) |
String |
path() |
ServerWebSocket |
pause()
Pause the
ReadStream, it sets the buffer in fetch mode and clears the actual demand. |
WebSocketBase |
pongHandler(Handler<Buffer> handler)
Set a pong message handler on the connection.
|
String |
query() |
void |
reject()
Reject the WebSocket.
|
void |
reject(int status)
Like
reject() but with a status. |
SocketAddress |
remoteAddress() |
ServerWebSocket |
resume()
Resume reading, and sets the buffer in
flowing mode. |
ServerWebSocket |
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.
|
Flowable<Buffer> |
toFlowable() |
Observable<Buffer> |
toObservable() |
io.vertx.reactivex.WriteStreamObserver<Buffer> |
toObserver() |
String |
toString() |
io.vertx.reactivex.WriteStreamSubscriber<Buffer> |
toSubscriber() |
String |
uri() |
ServerWebSocket |
write(Buffer data)
Write some data to the stream.
|
ServerWebSocket |
writeBinaryMessage(Buffer data)
Writes a (potentially large) piece of binary data to the connection.
|
ServerWebSocket |
writeFinalBinaryFrame(Buffer data)
Write a final WebSocket binary frame to the connection
|
ServerWebSocket |
writeFinalTextFrame(String text)
Write a final WebSocket text frame to the connection
|
ServerWebSocket |
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.
|
boolean |
writeQueueFull()
This will return
true if there are more bytes in the write queue than the value set using setWriteQueueMaxSize(int) |
WebSocketBase |
writeTextMessage(String text)
Writes a (potentially large) piece of text data to the connection.
|
clone, finalize, getClass, notify, notifyAll, wait, wait, waitnewInstancenewInstance, newInstancenewInstance, newInstancenewInstancepublic ServerWebSocket(ServerWebSocket delegate)
public ServerWebSocket getDelegate()
getDelegate in interface WebSocketBasegetDelegate in interface ReadStream<Buffer>getDelegate in interface StreamBasegetDelegate in interface WriteStream<Buffer>public Observable<Buffer> toObservable()
toObservable in interface ReadStream<Buffer>public Flowable<Buffer> toFlowable()
toFlowable in interface ReadStream<Buffer>public io.vertx.reactivex.WriteStreamObserver<Buffer> toObserver()
public io.vertx.reactivex.WriteStreamSubscriber<Buffer> toSubscriber()
public void end(Buffer t)
WebSocketBase.end(io.vertx.reactivex.core.buffer.Buffer) but writes some data to the stream before ending.end in interface WebSocketBaseend in interface WriteStream<Buffer>t - public boolean writeQueueFull()
true if there are more bytes in the write queue than the value set using setWriteQueueMaxSize(int)writeQueueFull in interface WebSocketBasewriteQueueFull in interface WriteStream<Buffer>public String 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.
binaryHandlerID in interface WebSocketBasepublic 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.
textHandlerID in interface WebSocketBasepublic String subProtocol()
null when the handler receives the websocket callback as the
handshake will not be completed yet.subProtocol in interface WebSocketBasepublic WebSocketBase writeTextMessage(String text)
writeTextMessage in interface WebSocketBasetext - the data to writepublic WebSocketBase 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.
writePing in interface WebSocketBasedata - the data to write, may be at most 125 bytespublic WebSocketBase 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.
writePong in interface WebSocketBasedata - the data to write, may be at most 125 bytespublic WebSocketBase textMessageHandler(Handler<String> handler)
textMessageHandler in interface WebSocketBasehandler - the handlerpublic WebSocketBase binaryMessageHandler(Handler<Buffer> handler)
handler(io.vertx.core.Handler<io.vertx.reactivex.core.buffer.Buffer>)
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).binaryMessageHandler in interface WebSocketBasehandler - the handlerpublic WebSocketBase 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.
pongHandler in interface WebSocketBasehandler - the handlerpublic void end()
WebSocketBase.close()end in interface WebSocketBaseend in interface WriteStream<Buffer>public void close()
close in interface WebSocketBasepublic void close(short statusCode)
close in interface WebSocketBasepublic void close(short statusCode,
String reason)
close in interface WebSocketBasepublic SocketAddress remoteAddress()
remoteAddress in interface WebSocketBasepublic SocketAddress localAddress()
localAddress in interface WebSocketBasepublic boolean isSsl()
isSsl in interface WebSocketBaseHttpConnection is encrypted via SSL/TLS.public ServerWebSocket exceptionHandler(Handler<Throwable> handler)
ReadStreamexceptionHandler in interface WebSocketBaseexceptionHandler in interface ReadStream<Buffer>exceptionHandler in interface StreamBaseexceptionHandler in interface WriteStream<Buffer>handler - the exception handlerpublic ServerWebSocket handler(Handler<Buffer> handler)
ReadStreamhandler in interface WebSocketBasehandler in interface ReadStream<Buffer>public ServerWebSocket 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 WebSocketBasepause in interface ReadStream<Buffer>public ServerWebSocket resume()
ReadStreamflowing mode.
If the ReadStream has been paused, reading will recommence on it.resume in interface WebSocketBaseresume in interface ReadStream<Buffer>public ServerWebSocket 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 WebSocketBasefetch in interface ReadStream<Buffer>public ServerWebSocket endHandler(Handler<Void> endHandler)
ReadStreamendHandler in interface WebSocketBaseendHandler in interface ReadStream<Buffer>public ServerWebSocket write(Buffer data)
WriteStreamWriteStream.writeQueueFull() method before writing. This is done automatically if using a Pump.write in interface WebSocketBasewrite in interface WriteStream<Buffer>data - the data to writepublic ServerWebSocket 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 WebSocketBasesetWriteQueueMaxSize in interface WriteStream<Buffer>maxSize - the max size of the write streampublic ServerWebSocket 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 WebSocketBasedrainHandler in interface WriteStream<Buffer>handler - the handlerpublic ServerWebSocket writeFrame(WebSocketFrame frame)
WebSocketBasewriteFrame in interface WebSocketBaseframe - the frame to writepublic ServerWebSocket writeFinalTextFrame(String text)
WebSocketBasewriteFinalTextFrame in interface WebSocketBasetext - The text to writepublic ServerWebSocket writeFinalBinaryFrame(Buffer data)
WebSocketBasewriteFinalBinaryFrame in interface WebSocketBasedata - The data to writepublic ServerWebSocket writeBinaryMessage(Buffer data)
WebSocketBasewriteBinaryMessage in interface WebSocketBasedata - the data to writepublic ServerWebSocket closeHandler(Handler<Void> handler)
WebSocketBasecloseHandler in interface WebSocketBasehandler - the handlerpublic ServerWebSocket frameHandler(Handler<WebSocketFrame> handler)
WebSocketBaseframeHandler in interface WebSocketBasehandler - the handlerpublic String uri()
public String path()
public String query()
public MultiMap headers()
public void accept()
public void reject()
Calling this method from the websocket handler when it is first passed to you gives you the opportunity to reject the websocket, which will cause the websocket handshake to fail by returning a response code.
You might use this method, if for example you only want to accept WebSockets with a particular path.
public void reject(int status)
reject() but with a status.status - public SSLSession sslSession()
public static ServerWebSocket newInstance(ServerWebSocket arg)
Copyright © 2018 Eclipse. All rights reserved.