new WebSocket(jWebSocket, server)
Represents an HTML 5 Websocket
Instances of this class are created and provided to the handler of an
HttpClient
when a successful websocket connect attempt occurs.
It implements both ReadStream
and WriteStream
so
it can be used with Pump
to pump data
with flow control.
Parameters:
Name | Type | Argument | Description |
---|---|---|---|
jWebSocket |
org.vertx.java.core.http.WebSocketBase | The java WebSocketBase object | |
server |
boolean |
<optional> |
whether this is a server-side websocket (default: false) |
- Source:
- See:
Extends
Methods
-
binaryHandlerID() → {string}
-
When a WebSocket is created it automatically registers an event handler with the eventbus, the ID of that handler is returned. 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:
id- Type
- string
-
close()
-
Close the websocket connection
- Source:
-
closeHandler(handler) → {WebSocket}
-
Set a closed
Handler
on the connection, the handler receives no parameters.Parameters:
Name Type Description handler
Handler The handler to call when the underlying connection has been closed - Source:
Returns:
this- Type
- WebSocket
-
dataHandler(handler)
-
Set a data handler. As data is read, the handler will be called with a Buffer containing the data read.
Parameters:
Name Type Description handler
BodyHandler the handler to call - Inherited From:
- Source:
-
drainHandler(handler)
-
Set a drain handler on the stream. If the write queue is full, then the handler will be called when the write queue has been reduced to maxSize/2. See
module:vertx/pump~Pump
for an example of this being used.Parameters:
Name Type Description handler
Handler the handler to call when the stream has been drained - Inherited From:
- Source:
-
endHandler(handler)
-
Set an end handler. Once the stream has ended, and there is no more data to be read, the handler will be called.
Parameters:
Name Type Description handler
Handler the handler to call - Inherited From:
- Source:
-
exceptionHandler(handler)
-
Set an exception handler.
Parameters:
Name Type Description handler
Handler the handler to call - Inherited From:
- Source:
-
exceptionHandler(handler)
-
Set an exception handler on the stream
Parameters:
Name Type Description handler
Handler the handler to call when an exception occurs - Inherited From:
- Source:
-
headers() → {module:vertx/multi_map~MultiMap}
-
The headers of the handshake request Only available if this is a server websocket.
- Source:
Returns:
-
path() → {string}
-
The path the websocket connect was attempted at. Only available if this is a server websocket.
- Source:
Returns:
path- Type
- string
-
pause()
-
Pause the
ReadStream
. While the stream is paused, no data will be sent to the data Handler- Inherited From:
- Source:
-
reject() → {module:vertx/http.WebSocket}
-
Reject the WebSocket. Sends 404 to client Only available if this is a server websocket.
- Source:
Returns:
-
resume()
-
Resume reading. If the
ReadStream
has been paused, reading will recommence on it.- Inherited From:
- Source:
-
textHandlerID() → {string}
-
When a WebSocket is created it automatically registers an event handler with the eventbus, the ID of that handler is returned. 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:
id- Type
- string
-
uri() → {string}
-
The URI the websocket handshake occured at
- Source:
Returns:
- Type
- string
-
write(data)
-
Write some data to the stream. The data is put on an internal write queue, and the write actually happens asynchronously. To avoid running out of memory by putting too much on the write queue, check the module:vertx/streams~WriteStream#writeQueueFull method before writing. This is done automatically if using a
module:vertx/pump~Pump
.Parameters:
Name Type Description data
module:vertx/buffer~Buffer the data to write - Inherited From:
- Source:
-
writeBinaryFrame(data)
-
Write data to the websocket as a binary frame
Parameters:
Name Type Description data
module:vertx/buffer~Buffer - Source:
-
writeQueueFull()
-
This will return
true
if there are more bytes in the write queue than the value set usingwriteQueueMaxSize
- Inherited From:
- Source:
-
writeQueueMaxSize(size)
-
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 thanmaxSize
bytes in the write queue. This is used as an indicator by classes such asPump
to provide flow control.Parameters:
Name Type Description size
number the size of the write queue - Inherited From:
- Source:
-
writeTextFrame(data)
-
Write data to the websocket as a text frame
Parameters:
Name Type Description data
module:vertx/buffer~Buffer - Source: