net.http.websocket
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.
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-openCalled when aWebSockethas been connected. Called with the WebSocket instance.:on-messageA textual/binary data has been received. Called with the WebSocket instance, the data, and whether this invocation completes the message.:on-pingA Ping message has been received. Called with the WebSocket instance and the ping message.:on-pongA Pong message has been received. Called with the WebSocket instance and the pong message.:on-closeReceives a Close message indicating the WebSocket’s input has been closed. Called with the WebSocket instance, the status code, and the reason.:on-errorAn 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:
uria websocket uriopts(optional), a map of::http-clientAn HttpClient - will use a default HttpClient if not provided:listenerA WebSocket$Listener - alternatively will be created from the handlers passed into opts: :on-open, :on-message, :on-ping, :on-pong, :on-close, :on-error:headersAdds the given name-value pair to the list of additional HTTP headers sent during the opening handshake.:connect-timeoutSets a timeout for establishing a WebSocket connection (in millis).:subprotocolsSets 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