public interface ServerWebSocket extends WebSocketBase
Instances of this class are passed into a HttpServer.websocketHandler(io.vertx.core.Handler<io.vertx.core.http.ServerWebSocket>)
or provided
when a WebSocket handshake is manually HttpServerRequest.upgrade()
ed.
Modifier and Type | Method and Description |
---|---|
void |
accept()
Accept the WebSocket and terminate the WebSocket handshake.
|
ServerWebSocket |
closeHandler(Handler<Void> handler)
Set a close handler.
|
ServerWebSocket |
drainHandler(Handler<Void> handler)
Set a drain handler on the stream.
|
ServerWebSocket |
endHandler(Handler<Void> endHandler)
Set an end handler.
|
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 |
handler(Handler<Buffer> handler)
Set a data handler.
|
MultiMap |
headers() |
String |
path() |
ServerWebSocket |
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.
|
String |
query() |
void |
reject()
Reject the WebSocket.
|
void |
reject(int status)
Like
reject() but with a status . |
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 |
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
|
binaryHandlerID, binaryMessageHandler, close, close, close, end, isSsl, localAddress, pongHandler, remoteAddress, subProtocol, textHandlerID, textMessageHandler, writePing, writePong, writeTextMessage
end, writeQueueFull
ServerWebSocket exceptionHandler(Handler<Throwable> handler)
ReadStream
exceptionHandler
in interface ReadStream<Buffer>
exceptionHandler
in interface StreamBase
exceptionHandler
in interface WebSocketBase
exceptionHandler
in interface WriteStream<Buffer>
handler
- the exception handlerServerWebSocket handler(Handler<Buffer> handler)
ReadStream
handler
in interface ReadStream<Buffer>
handler
in interface WebSocketBase
ServerWebSocket pause()
ReadStream
ReadStream
, 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>
pause
in interface WebSocketBase
ServerWebSocket resume()
ReadStream
flowing
mode.
If the ReadStream
has been paused, reading will recommence on it.resume
in interface ReadStream<Buffer>
resume
in interface WebSocketBase
ServerWebSocket fetch(long amount)
ReadStream
amount
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>
fetch
in interface WebSocketBase
ServerWebSocket endHandler(Handler<Void> endHandler)
ReadStream
endHandler
in interface ReadStream<Buffer>
endHandler
in interface WebSocketBase
ServerWebSocket write(Buffer data)
WriteStream
WriteStream.writeQueueFull()
method before writing. This is done automatically if using a Pump
.write
in interface WebSocketBase
write
in interface WriteStream<Buffer>
data
- the data to writeServerWebSocket setWriteQueueMaxSize(int maxSize)
WriteStream
maxSize
. 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 WebSocketBase
setWriteQueueMaxSize
in interface WriteStream<Buffer>
maxSize
- the max size of the write streamServerWebSocket drainHandler(Handler<Void> handler)
WriteStream
Pump
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 WebSocketBase
drainHandler
in interface WriteStream<Buffer>
handler
- the handlerServerWebSocket writeFrame(WebSocketFrame frame)
WebSocketBase
writeFrame
in interface WebSocketBase
frame
- the frame to writeServerWebSocket writeFinalTextFrame(String text)
WebSocketBase
writeFinalTextFrame
in interface WebSocketBase
text
- The text to writeServerWebSocket writeFinalBinaryFrame(Buffer data)
WebSocketBase
writeFinalBinaryFrame
in interface WebSocketBase
data
- The data to writeServerWebSocket writeBinaryMessage(Buffer data)
WebSocketBase
writeBinaryMessage
in interface WebSocketBase
data
- the data to writeServerWebSocket closeHandler(Handler<Void> handler)
WebSocketBase
closeHandler
in interface WebSocketBase
handler
- the handlerServerWebSocket frameHandler(Handler<WebSocketFrame> handler)
WebSocketBase
frameHandler
in interface WebSocketBase
handler
- the handlerString uri()
String path()
String query()
MultiMap headers()
void accept()
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 502 response code.
You might use this method, if for example you only want to accept WebSockets with a particular path.
void reject(int status)
reject()
but with a status
.SSLSession sslSession()
sslSession
in interface WebSocketBase
SSLSession
X509Certificate[] peerCertificateChain() throws SSLPeerUnverifiedException
sslSession()
to
access that method.peerCertificateChain
in interface WebSocketBase
SSLPeerUnverifiedException
- SSL peer's identity has not been verified.SSLSession.getPeerCertificateChain()
,
sslSession()
Copyright © 2018 Eclipse. All rights reserved.