new ServerWebSocket()
Represents a server side WebSocket.
- Source:
Methods
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.
- Source:
binaryHandlerID() → {string}
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.
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.
- Source:
Returns:
the binary handler id
-
Type
-
string
binaryMessageHandler(handler) → {WebSocketBase}
Set a binary message handler on the connection. This handler serves a similar purpose to ServerWebSocket#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).
Parameters:
| Name |
Type |
Description |
handler |
function
|
the handler |
- Source:
Returns:
a reference to this, so the API can be used fluently
-
Type
-
WebSocketBase
close(statusCode, reason, handler)
Same as but with an handler called when the operation completes
Parameters:
| Name |
Type |
Description |
statusCode |
number
|
|
reason |
string
|
|
handler |
function
|
|
- Source:
closeHandler(handler) → {ServerWebSocket}
Parameters:
| Name |
Type |
Description |
handler |
function
|
|
- Source:
Returns:
-
Type
-
ServerWebSocket
closeReason() → {string}
Returns the reason message received when the WebSocket was closed by the other side, otherwise null.
- Source:
Returns:
-
Type
-
string
closeStatusCode() → {number}
Returns the status code received when the WebSocket was closed by the other side, otherwise null.
- Source:
Returns:
-
Type
-
number
drainHandler(handler) → {ServerWebSocket}
Parameters:
| Name |
Type |
Description |
handler |
function
|
|
- Source:
Returns:
-
Type
-
ServerWebSocket
end(handler)
Calls WebSocketBase#close
Parameters:
| Name |
Type |
Description |
handler |
function
|
|
- Source:
endHandler(endHandler) → {ServerWebSocket}
Parameters:
| Name |
Type |
Description |
endHandler |
function
|
|
- Source:
Returns:
-
Type
-
ServerWebSocket
exceptionHandler(handler) → {ServerWebSocket}
Parameters:
| Name |
Type |
Description |
handler |
function
|
|
- Source:
Returns:
-
Type
-
ServerWebSocket
fetch(amount) → {ServerWebSocket}
Parameters:
| Name |
Type |
Description |
amount |
number
|
|
- Source:
Returns:
-
Type
-
ServerWebSocket
frameHandler(handler) → {ServerWebSocket}
Parameters:
| Name |
Type |
Description |
handler |
function
|
|
- Source:
Returns:
-
Type
-
ServerWebSocket
handler(handler) → {ServerWebSocket}
Parameters:
| Name |
Type |
Description |
handler |
function
|
|
- Source:
Returns:
-
Type
-
ServerWebSocket
- Source:
Returns:
the headers in the WebSocket handshake
-
Type
-
MultiMap
isClosed() → {boolean}
- Source:
Returns:
true if the WebSocket is closed
-
Type
-
boolean
isSsl() → {boolean}
- Source:
Returns:
true if this HttpConnection is encrypted via SSL/TLS.
-
Type
-
boolean
localAddress() → {SocketAddress}
- Source:
Returns:
the local address for this socket
-
Type
-
SocketAddress
path() → {string}
- Source:
Returns:
the WebSocket handshake path.
-
Type
-
string
pause() → {ServerWebSocket}
- Source:
Returns:
-
Type
-
ServerWebSocket
pipe() → {Pipe}
Pause this stream and return a to transfer the elements of this stream to a destination .
The stream will be resumed when the pipe will be wired to a
WriteStream.
- Source:
Returns:
a pipe
-
Type
-
Pipe
pipeTo(dst, handler)
Pipe this
ReadStream to the
WriteStream.
Elements emitted by this stream will be written to the write stream until this stream ends or fails.
Once this stream has ended or failed, the write stream will be ended and the handler will be
called with the result.
Parameters:
| Name |
Type |
Description |
dst |
WriteStream
|
the destination write stream |
handler |
function
|
|
- Source:
pongHandler(handler) → {WebSocketBase}
Set a pong frame handler on the connection. This handler will be invoked every time a pong frame is received
on the server, and can be used by both clients and servers since the RFC 6455
section 5.5.2 and
section 5.5.3 do not
specify whether the client or server sends a ping.
Pong frames may be at most 125 bytes (octets).
There is no ping handler since ping frames should immediately be responded to with a pong frame with identical content
Pong frames may be received unsolicited.
Parameters:
| Name |
Type |
Description |
handler |
function
|
the handler |
- Source:
Returns:
a reference to this, so the API can be used fluently
-
Type
-
WebSocketBase
query() → {string}
- Source:
Returns:
the WebSocket handshake query string.
-
Type
-
string
reject(status)
Like ServerWebSocket#reject but with a status.
Parameters:
| Name |
Type |
Description |
status |
number
|
|
- Source:
remoteAddress() → {SocketAddress}
- Source:
Returns:
the remote address for this socket
-
Type
-
SocketAddress
resume() → {ServerWebSocket}
- Source:
Returns:
-
Type
-
ServerWebSocket
setHandshake(future)
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 status code
- rejected when the
future is succeeds with an HTTP status code different than
- 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 ServerWebSocket#close method
will try to accept the handshake and close the WebSocket afterward. Thus it is advised to try to complete
the
future with or .
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:
| Name |
Type |
Description |
future |
Promise
|
the future to complete with |
- Source:
setWriteQueueMaxSize(maxSize) → {ServerWebSocket}
Parameters:
| Name |
Type |
Description |
maxSize |
number
|
|
- Source:
Returns:
-
Type
-
ServerWebSocket
subProtocol() → {string}
Returns the WebSocket sub protocol selected by the WebSocket handshake.
On the server, the value will be
null when the handler receives the websocket callback as the
handshake will not be completed yet.
- Source:
Returns:
-
Type
-
string
textHandlerID() → {string}
When a
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.
- Source:
Returns:
-
Type
-
string
textMessageHandler(handler) → {WebSocketBase}
Set a text message handler on the connection. This handler will be called similar to the
, but the buffer will be converted to a String first
Parameters:
| Name |
Type |
Description |
handler |
function
|
the handler |
- Source:
Returns:
a reference to this, so the API can be used fluently
-
Type
-
WebSocketBase
uri() → {string}
- Source:
Returns:
-
Type
-
string
write(data, handler)
Same as but with an handler called when the operation completes
Parameters:
| Name |
Type |
Description |
data |
Buffer
|
|
handler |
function
|
|
- Source:
writeBinaryMessage(data, handler) → {ServerWebSocket}
Parameters:
| Name |
Type |
Description |
data |
Buffer
|
|
handler |
function
|
|
- Source:
Returns:
-
Type
-
ServerWebSocket
writeFinalBinaryFrame(data, handler) → {ServerWebSocket}
Parameters:
| Name |
Type |
Description |
data |
Buffer
|
|
handler |
function
|
|
- Source:
Returns:
-
Type
-
ServerWebSocket
writeFinalTextFrame(text, handler) → {ServerWebSocket}
Parameters:
| Name |
Type |
Description |
text |
string
|
|
handler |
function
|
|
- Source:
Returns:
-
Type
-
ServerWebSocket
writeFrame(frame, handler) → {ServerWebSocket}
Parameters:
| Name |
Type |
Description |
frame |
WebSocketFrame
|
|
handler |
function
|
|
- Source:
Returns:
-
Type
-
ServerWebSocket
writePing(data) → {WebSocketBase}
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:
| Name |
Type |
Description |
data |
Buffer
|
the data to write, may be at most 125 bytes |
- Source:
Returns:
a future completed with the result
-
Type
-
WebSocketBase
writePong(data) → {WebSocketBase}
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:
| Name |
Type |
Description |
data |
Buffer
|
the data to write, may be at most 125 bytes |
- Source:
Returns:
a reference to this, so the API can be used fluently
-
Type
-
WebSocketBase
writeQueueFull() → {boolean}
This will return true if there are more bytes in the write queue than the value set using ServerWebSocket#setWriteQueueMaxSize
- Source:
Returns:
true if write queue is full
-
Type
-
boolean
writeTextMessage(text, handler) → {ServerWebSocket}
Parameters:
| Name |
Type |
Description |
text |
string
|
|
handler |
function
|
|
- Source:
Returns:
-
Type
-
ServerWebSocket