The websocket client under fire.socket, on nothing but Java 8.
This used to be gniazdo, which brought seven Jetty 9.4 jars onto every consumer's classpath — Jetty 9.4 has been end of life since 2022 — for the one websocket fire.socket opens. The JDK's own client would do, but it arrived in Java 11 and fire supports 8. So this is RFC 6455 directly: a TLS socket, an HTTP upgrade, and a frame format small enough to fit in a screen. What fire.socket needs from it is three things — open one with callbacks, send a text message, close it — and that is all this is.
Text is delivered whole: a message that arrives in several frames is gathered as bytes and decoded once, at the end, so a multi-byte character split across a frame boundary survives. Pings are answered. Sends are serialised on one lock, which the reader's pongs share.
The websocket client under fire.socket, on nothing but Java 8. This used to be gniazdo, which brought seven Jetty 9.4 jars onto every consumer's classpath — Jetty 9.4 has been end of life since 2022 — for the one websocket fire.socket opens. The JDK's own client would do, but it arrived in Java 11 and fire supports 8. So this is RFC 6455 directly: a TLS socket, an HTTP upgrade, and a frame format small enough to fit in a screen. What fire.socket needs from it is three things — open one with callbacks, send a text message, close it — and that is all this is. Text is delivered whole: a message that arrives in several frames is gathered as bytes and decoded once, at the end, so a multi-byte character split across a frame boundary survives. Pings are answered. Sends are serialised on one lock, which the reader's pongs share.
(close! {:keys [closing closed] :as conn})Start a normal close. The peer's answering close arrives at on-close and ends the connection. Closing twice is a no-op.
Start a normal close. The peer's answering close arrives at on-close and ends the connection. Closing twice is a no-op.
(connect url
&
{:keys [on-receive on-close on-error]
:or {on-receive (fn [_]) on-close (fn [_ _]) on-error (fn [_])}})Open a websocket to url (ws:// or wss://) and return a connection.
on-receive gets each whole text message as a string; on-close gets the
status code and reason once, however the connection ended; on-error gets
a Throwable when the connection fails after it opened. Throws if the
connection cannot be made or the upgrade is refused.
Open a websocket to `url` (ws:// or wss://) and return a connection. `on-receive` gets each whole text message as a string; `on-close` gets the status code and reason once, however the connection ended; `on-error` gets a Throwable when the connection fails after it opened. Throws if the connection cannot be made or the upgrade is refused.
(encode-frame opcode payload)One masked client frame: a final frame of opcode carrying payload.
One masked client frame: a final frame of `opcode` carrying `payload`.
(read-frame in)The next frame off in, as {:fin? :opcode :payload}. Blocks until one is
there; throws EOFException when the stream ends first. A masked frame from
the server is against the spec, but is unmasked rather than refused.
The next frame off `in`, as {:fin? :opcode :payload}. Blocks until one is
there; throws EOFException when the stream ends first. A masked frame from
the server is against the spec, but is unmasked rather than refused.(send! conn message)Send one text message, whole.
Send one text message, whole.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |