Top Description Methods
io.vertx.core.http

public Interface ServerWebSocket

extends WebSocketBase
Known Direct Implementers
io.vertx.core.http.impl.ServerWebSocketImpl
Annotations
@VertxGen
Imports
io.vertx.codegen.annotations.GenIgnore, .Nullable, .VertxGen, io.vertx.core.AsyncResult, .Future, .Handler, .Promise, io.vertx.core.buffer.Buffer, io.vertx.core.net.HostAndPort, javax.net.ssl.SSLPeerUnverifiedException, .SSLSession, javax.security.cert.X509Certificate

Represents a server side WebSocket.

Instances of this class are passed into a io.vertx.core.http.HttpServer#webSocketHandler or provided when a WebSocket handshake is manually HttpServerRequest#toWebSocketed.

Author
Tim Fox

Method Summary

Modifier and TypeMethod and Description
public void
accept()
Deprecated instead use ServerWebSocketHandshake#accept()

Accept the WebSocket and terminate the WebSocket handshake.

public @Nullable HostAndPort

Returns:

the WebSocket handshake authority
authority
()

public Future<Void>
close()

Redeclares io.vertx.core.http.WebSocketBase.close.

Close the WebSocket sending the default close frame.

public ServerWebSocket
public ServerWebSocket
public ServerWebSocket
public ServerWebSocket
public ServerWebSocket
fetch(long amount)

Redeclares io.vertx.core.http.WebSocketBase.fetch.

Fetch the specified amount of elements.

public ServerWebSocket
public ServerWebSocket
public @Nullable String

Returns:

the WebSocket handshake host
host
()
Deprecated use authority() instead

public String

Returns:

the WebSocket handshake path.
path
()

public ServerWebSocket
pause()

Redeclares io.vertx.core.http.WebSocketBase.pause.

Pause the ReadStream, it sets the buffer in fetch mode and clears the actual demand.

public @Nullable String

Returns:

the WebSocket handshake query string.
query
()

public void
reject()
Deprecated instead use ServerWebSocketHandshake#reject()

Reject the WebSocket.

public void
reject(int status)
Deprecated instead use ServerWebSocketHandshake#reject(int)

Like reject() but with a status.

public ServerWebSocket
resume()

Redeclares io.vertx.core.http.WebSocketBase.resume.

Resume reading, and sets the buffer in flowing mode.

public @Nullable String

Returns:

the WebSocket handshake scheme
scheme
()

public void
setHandshake(Future<Integer>
the future to complete with
future
,
Handler<AsyncResult<Integer>>
the completion handler
handler
)
Deprecated instead use ServerWebSocketHandshake

Set an asynchronous result for the handshake, upon completion of the specified future, the WebSocket will either be

  • accepted when the future succeeds with the HTTP 101 status code
  • rejected when the future is succeeds with an HTTP status code different than 101
  • rejected when the future fails with the HTTP status code 500
public Future<Integer>
setHandshake(Future<Integer> future)
Deprecated instead use ServerWebSocketHandshake

Like setHandshake(Future, Handler) but returns a Future of the asynchronous result

public ServerWebSocket
setWriteQueueMaxSize(int
the max size of the write stream
maxSize
)

Redeclares io.vertx.core.http.WebSocketBase.setWriteQueueMaxSize.

Set the maximum size of the write queue to maxSize.

public SSLSession

Returns:

SSLSession associated with the underlying socket. Returns null if connection is not SSL.
sslSession
()

Redeclares io.vertx.core.http.WebSocketBase.sslSession.

public String
uri()

public ServerWebSocket
writeBinaryMessage(Buffer data, Handler<AsyncResult<Void>> handler)

Redeclares io.vertx.core.http.WebSocketBase.writeBinaryMessage.

References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

Same as writeBinaryMessage(Buffer) but with an handler called when the operation completes

public ServerWebSocket
writeFinalBinaryFrame(Buffer data, Handler<AsyncResult<Void>> handler)

Redeclares io.vertx.core.http.WebSocketBase.writeFinalBinaryFrame.

References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

Same as writeFinalBinaryFrame(Buffer, Handler) but with an handler called when the operation completes

public ServerWebSocket
writeFinalTextFrame(String text, Handler<AsyncResult<Void>> handler)

Redeclares io.vertx.core.http.WebSocketBase.writeFinalTextFrame.

Same as writeFinalTextFrame(String, Handler) but with an handler called when the operation completes

public ServerWebSocket
writeFrame(WebSocketFrame frame, Handler<AsyncResult<Void>> handler)

Redeclares io.vertx.core.http.WebSocketBase.writeFrame.

Same as writeFrame(WebSocketFrame) but with an handler called when the operation completes

public ServerWebSocket
writePing(Buffer
the data to write, may be at most 125 bytes
data
,
Handler<AsyncResult<Void>>
called when the ping frame has been successfully written
handler
)

Redeclares io.vertx.core.http.WebSocketBase.writePing.

References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

Writes a ping frame to the connection.

public ServerWebSocket
writePong(Buffer
the data to write, may be at most 125 bytes
data
,
Handler<AsyncResult<Void>>
called when the pong frame has been successfully written
handler
)

Redeclares io.vertx.core.http.WebSocketBase.writePong.

References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

Writes a pong frame to the connection.

public ServerWebSocket
writeTextMessage(String text, Handler<AsyncResult<Void>> handler)

Redeclares io.vertx.core.http.WebSocketBase.writeTextMessage.

Same as writeTextMessage(String) but with an handler called when the operation completes

Inherited from io.vertx.core.http.WebSocketBase:
binaryHandlerIDbinaryMessageHandlerclosecloseclosecloseclosecloseHandlercloseReasoncloseStatusCodeendendframeHandlerheadersisClosedisSsllocalAddresspeerCertificateChainpeerCertificatespongHandlerremoteAddresssubProtocoltextHandlerIDtextMessageHandlerwriteBinaryMessagewriteFinalBinaryFramewriteFinalTextFramewriteFramewritePingwritePongwriteTextMessage

Method Detail

acceptback to summary
public void accept()

Deprecated

instead use ServerWebSocketHandshake#accept()

Accept the WebSocket and terminate the WebSocket handshake.

This method should be called from the WebSocket handler to explicitly accept the WebSocket and terminate the WebSocket handshake.

Annotations
@Deprecated
Exceptions
IllegalStateException:
when the WebSocket handshake is already set
authorityback to summary
public @Nullable HostAndPort authority()
Returns:@Nullable HostAndPort

the WebSocket handshake authority

closeback to summary
public Future<Void> close()

Redeclares io.vertx.core.http.WebSocketBase.close.

Doc from io.vertx.core.http.WebSocketBase.close.

Close the WebSocket sending the default close frame.

No more messages can be sent.

The WebSocket handshake will be accepted when it hasn't yet been settled or when an asynchronous handshake is in progress.

Returns:Future<Void>

a future completed with the result

Annotations
@Override
closeHandlerback to summary
public ServerWebSocket closeHandler(Handler<Void> handler)
Annotations
@Override
drainHandlerback to summary
public ServerWebSocket drainHandler(Handler<Void> handler)

Redeclares io.vertx.core.http.WebSocketBase.drainHandler.

Annotations
@Override
endHandlerback to summary
public ServerWebSocket endHandler(Handler<Void> endHandler)

Redeclares io.vertx.core.http.WebSocketBase.endHandler.

Annotations
@Override
exceptionHandlerback to summary
public ServerWebSocket exceptionHandler(Handler<Throwable> handler)

Redeclares io.vertx.core.http.WebSocketBase.exceptionHandler.

Annotations
@Override
fetchback to summary
public ServerWebSocket fetch(long amount)

Redeclares io.vertx.core.http.WebSocketBase.fetch.

Doc from io.vertx.core.streams.ReadStream.fetch.

Fetch the specified 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.

Returns:ServerWebSocket

a reference to this, so the API can be used fluently

Annotations
@Override
frameHandlerback to summary
public ServerWebSocket frameHandler(Handler<WebSocketFrame> handler)
Annotations
@Override
handlerback to summary
public ServerWebSocket handler(Handler<Buffer> handler)

Redeclares io.vertx.core.http.WebSocketBase.handler.

Annotations
@Override
hostback to summary
public @Nullable String host()

Deprecated

use authority() instead

Returns:@Nullable String

the WebSocket handshake host

Annotations
@Deprecated
pathback to summary
public String path()
Returns:String

the WebSocket handshake path.

pauseback to summary
public ServerWebSocket pause()

Redeclares io.vertx.core.http.WebSocketBase.pause.

Doc from io.vertx.core.streams.ReadStream.pause.

Pause the 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.

Returns:ServerWebSocket

a reference to this, so the API can be used fluently

Annotations
@Override
queryback to summary
public @Nullable String query()
Returns:@Nullable String

the WebSocket handshake query string.

rejectback to summary
public void reject()

Deprecated

instead use ServerWebSocketHandshake#reject()

Reject the WebSocket.

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.

Annotations
@Deprecated
Exceptions
IllegalStateException:
when the WebSocket handshake is already set
rejectback to summary
public void reject(int status)

Deprecated

instead use ServerWebSocketHandshake#reject(int)

Like reject() but with a status.

Annotations
@Deprecated
resumeback to summary
public ServerWebSocket resume()

Redeclares io.vertx.core.http.WebSocketBase.resume.

Doc from io.vertx.core.streams.ReadStream.resume.

Resume reading, and sets the buffer in flowing mode.

If the ReadStream has been paused, reading will recommence on it.

Returns:ServerWebSocket

a reference to this, so the API can be used fluently

Annotations
@Override
schemeback to summary
public @Nullable String scheme()
Returns:@Nullable String

the WebSocket handshake scheme

setHandshakeback to summary
public void setHandshake(Future<Integer> future, Handler<AsyncResult<Integer>> handler)

Deprecated

instead use ServerWebSocketHandshake

Set an asynchronous result for the handshake, upon completion of the specified future, the WebSocket will either be

  • accepted when the future succeeds with the HTTP 101 status code
  • rejected when the future is succeeds with an HTTP status code different than 101
  • rejected when the future fails with the HTTP status code 500
The provided future might be completed by the WebSocket itself, e.g calling the close() method will try to accept the handshake and close the WebSocket afterward. Thus it is advised to try to complete the future with Promise#tryComplete or Promise#tryFail.

This method should be called from the WebSocket handler to explicitly set an asynchronous handshake.

Calling this method will override the future completion handler.

Parameters
future:Future<Integer>

the future to complete with

handler:Handler<AsyncResult<Integer>>

the completion handler

Annotations
@Deprecated
Exceptions
IllegalStateException:
when the WebSocket has already an asynchronous result
setHandshakeback to summary
public Future<Integer> setHandshake(Future<Integer> future)

Deprecated

instead use ServerWebSocketHandshake

Like setHandshake(Future, Handler) but returns a Future of the asynchronous result

Annotations
@Deprecated
setWriteQueueMaxSizeback to summary
public ServerWebSocket setWriteQueueMaxSize(int maxSize)

Redeclares io.vertx.core.http.WebSocketBase.setWriteQueueMaxSize.

Doc from io.vertx.core.streams.WriteStream.setWriteQueueMaxSize.

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 items in the write queue. This is used as an indicator by classes such as Pipe to provide flow control.

The value is defined by the implementation of the stream, e.g in bytes for a io.vertx.core.net.NetSocket, etc...

Parameters
maxSize:int

the max size of the write stream

Returns:ServerWebSocket

a reference to this, so the API can be used fluently

Annotations
@Override
sslSessionback to summary
public SSLSession sslSession()

Redeclares io.vertx.core.http.WebSocketBase.sslSession.

Returns:SSLSession

SSLSession associated with the underlying socket. Returns null if connection is not SSL.

Annotations
@GenIgnore:permitted-type
See Also
javax.net.ssl.SSLSession
uriback to summary
public String uri()
writeBinaryMessageback to summary
public ServerWebSocket writeBinaryMessage(Buffer data, Handler<AsyncResult<Void>> handler)

Redeclares io.vertx.core.http.WebSocketBase.writeBinaryMessage.

Doc from io.vertx.core.http.WebSocketBase.writeBinaryMessage.

References Deprecated

Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Same as writeBinaryMessage(Buffer) but with an handler called when the operation completes

Annotations
@Override
writeFinalBinaryFrameback to summary
public ServerWebSocket writeFinalBinaryFrame(Buffer data, Handler<AsyncResult<Void>> handler)

Redeclares io.vertx.core.http.WebSocketBase.writeFinalBinaryFrame.

Doc from io.vertx.core.http.WebSocketBase.writeFinalBinaryFrame.

References Deprecated

Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Same as writeFinalBinaryFrame(Buffer, Handler) but with an handler called when the operation completes

Annotations
@Override
writeFinalTextFrameback to summary
public ServerWebSocket writeFinalTextFrame(String text, Handler<AsyncResult<Void>> handler)

Redeclares io.vertx.core.http.WebSocketBase.writeFinalTextFrame.

Doc from io.vertx.core.http.WebSocketBase.writeFinalTextFrame.

Same as writeFinalTextFrame(String, Handler) but with an handler called when the operation completes

Annotations
@Override
writeFrameback to summary
public ServerWebSocket writeFrame(WebSocketFrame frame, Handler<AsyncResult<Void>> handler)

Redeclares io.vertx.core.http.WebSocketBase.writeFrame.

Doc from io.vertx.core.http.WebSocketBase.writeFrame.

Same as writeFrame(WebSocketFrame) but with an handler called when the operation completes

Annotations
@Override
writePingback to summary
public ServerWebSocket writePing(Buffer data, Handler<AsyncResult<Void>> handler)

Redeclares io.vertx.core.http.WebSocketBase.writePing.

Doc from io.vertx.core.http.WebSocketBase.writePing.

References Deprecated

Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Writes a ping frame to the connection. This will be written in a single frame. Ping frames may be at most 125 bytes (octets).

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 section 5.5.2.

There is no handler for ping frames because RFC 6455 clearly states that the only response to a ping frame is a pong frame with identical contents.

Parameters
data:Buffer

the data to write, may be at most 125 bytes

handler:Handler<AsyncResult<Void>>

called when the ping frame has been successfully written

Returns:ServerWebSocket

a reference to this, so the API can be used fluently

Annotations
@Override
writePongback to summary
public ServerWebSocket writePong(Buffer data, Handler<AsyncResult<Void>> handler)

Redeclares io.vertx.core.http.WebSocketBase.writePong.

Doc from io.vertx.core.http.WebSocketBase.writePong.

References Deprecated

Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Writes a pong frame to the connection. This will be written in a single frame. Pong frames may be at most 125 bytes (octets).

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 frame, as the server and client both handle responding to a ping from with a pong from 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.

Parameters
data:Buffer

the data to write, may be at most 125 bytes

handler:Handler<AsyncResult<Void>>

called when the pong frame has been successfully written

Returns:ServerWebSocket

a reference to this, so the API can be used fluently

Annotations
@Override
writeTextMessageback to summary
public ServerWebSocket writeTextMessage(String text, Handler<AsyncResult<Void>> handler)

Redeclares io.vertx.core.http.WebSocketBase.writeTextMessage.

Doc from io.vertx.core.http.WebSocketBase.writeTextMessage.

Same as writeTextMessage(String) but with an handler called when the operation completes

Annotations
@Override