Base WebSocket implementation.

It implements both and so it can be used with Pump to pump data with flow control.

no type hierarchy

Inherited Attributes
Attributes inherited from: Object
hash, string
Methods
binaryHandlerIDshared 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.

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.

binaryMessageHandlershared WebSocketBase binaryMessageHandler(Anything(Buffer)? handler)

Set a binary message handler on the connection. This handler serves a similar purpose to 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 isFinal to find the boundaries).

Parameters:
  • handler

    the handler

closeshared void close()

Close the WebSocket.

closeHandlershared WebSocketBase closeHandler(Anything()? handler)

Set a close handler. This will be called when the WebSocket is closed.

Parameters:
  • handler

    the handler

drainHandlershared WebSocketBase drainHandler(Anything()? handler)
endshared void end()

Calls close

endshared void end(Buffer t)

Same as end but writes some data to the stream before ending.

endHandlershared WebSocketBase endHandler(Anything()? endHandler)
exceptionHandlershared WebSocketBase exceptionHandler(Anything(Throwable)? handler)
frameHandlershared WebSocketBase frameHandler(Anything(WebSocketFrame)? handler)

Set a frame handler on the connection. This handler will be called when frames are read on the connection.

Parameters:
  • handler

    the handler

handlershared WebSocketBase handler(Anything(Buffer)? handler)
isSslshared Boolean isSsl()
localAddressshared SocketAddress localAddress()
pauseshared WebSocketBase pause()
remoteAddressshared SocketAddress remoteAddress()
resumeshared WebSocketBase resume()
setWriteQueueMaxSizeshared WebSocketBase setWriteQueueMaxSize(Integer maxSize)
textHandlerIDshared 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.

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.

textMessageHandlershared WebSocketBase textMessageHandler(Anything(String)? handler)

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:
  • handler

    the handler

writeshared WebSocketBase write(Buffer data)
writeBinaryMessageshared WebSocketBase writeBinaryMessage(Buffer data)

Writes a (potentially large) piece of binary data to the connection. This data might be written as multiple frames if it exceeds the maximum WebSocket frame size.

Parameters:
  • data

    the data to write

writeFinalBinaryFrameshared WebSocketBase writeFinalBinaryFrame(Buffer data)

Write a final WebSocket binary frame to the connection

Parameters:
  • data

    The data to write

writeFinalTextFrameshared WebSocketBase writeFinalTextFrame(String text)

Write a final WebSocket text frame to the connection

Parameters:
  • text

    The text to write

writeFrameshared WebSocketBase writeFrame(WebSocketFrame frame)

Write a WebSocket frame to the connection

Parameters:
  • frame

    the frame to write

writeQueueFullshared Boolean writeQueueFull()

This will return true if there are more bytes in the write queue than the value set using setWriteQueueMaxSize

writeTextMessageshared WebSocketBase writeTextMessage(String text)

Writes a (potentially large) piece of text data to the connection. This data might be written as multiple frames if it exceeds the maximum WebSocket frame size.

Parameters:
  • text

    the data to write

Inherited Methods
Methods inherited from: Object
equals
Methods inherited from: ReadStream<T>
Methods inherited from: StreamBase
Methods inherited from: WriteStream<T>