net.http.websocket

abort!

added in 3.0

(abort! ws)

Closes this WebSocket’s input and output abruptly.

close!

added in 3.0

(close! ws)(close! ws status-code reason)

Initiates an orderly closure of this WebSocket’s output by sending a Close message with the given status code and the reason.

ping!

added in 3.0

(ping! ws data)

Sends a Ping message with bytes from the given buffer.

pong!

added in 3.0

(pong! ws data)

Sends a Pong message with bytes from the given buffer.

request->WebSocketListener

added in 3.0

(request->WebSocketListener {:keys [on-open on-message on-ping on-pong on-close on-error]})

Constructs a new WebSocket listener to receive events for a given WebSocket connection.

Takes a map of:

  • :on-open Called when a WebSocket has been connected. Called with the WebSocket instance.
  • :on-message A textual/binary data has been received. Called with the WebSocket instance, the data, and whether this invocation completes the message.
  • :on-ping A Ping message has been received. Called with the WebSocket instance and the ping message.
  • :on-pong A Pong message has been received. Called with the WebSocket instance and the pong message.
  • :on-close Receives a Close message indicating the WebSocket’s input has been closed. Called with the WebSocket instance, the status code, and the reason.
  • :on-error An error has occurred. Called with the WebSocket instance and the error.

send!

added in 3.0

(send! ws data)(send! ws data {:keys [last?], :or {last? true}})

Sends a message to the WebSocket.

data can be a CharSequence (e.g. string) or ByteBuffer

Sendable

protocol

Protocol to represent sendable message types for a WebSocket. Useful for custom extensions.

members

-send!

(-send! data last? ws)

websocket

added in 3.0

(websocket uri {:keys [on-open on-message on-ping on-pong on-close on-error], :as opts})

Builds a new WebSocket connection from a request object and returns a future connection.

Arguments:

  • uri a websocket uri
  • opts (optional), a map of:
  • :http-client An HttpClient - will use a default HttpClient if not provided
  • :listener A WebSocket$Listener - alternatively will be created from the handlers passed into opts: :on-open, :on-message, :on-ping, :on-pong, :on-close, :on-error
  • :headers Adds the given name-value pair to the list of additional HTTP headers sent during the opening handshake.
  • :connect-timeout Sets a timeout for establishing a WebSocket connection (in millis).
  • :subprotocols Sets a request for the given subprotocols.

websocket*

added in 3.0

(websocket* {:keys [uri listener http-client headers connect-timeout subprotocols], :as opts})

Same as websocket but take all arguments as a single map