Skip to content

Instantly share code, notes, and snippets.

@shilder
Created February 13, 2018 15:25
Show Gist options
  • Save shilder/39966c25daaba51d2d122d6acd8e51a4 to your computer and use it in GitHub Desktop.
Save shilder/39966c25daaba51d2d122d6acd8e51a4 to your computer and use it in GitHub Desktop.
Aleph websocket simplest client
(require '[aleph.http :as http])
(require '[manifold.stream :as s])
(require '[manifold.deferred :as d])
;; connection will hold duplex stream
;; deref will block while client is connecting
(defonce connection @(http/websocket-client "wss://url/"))
;; calls provided callback with every message on websocket
(s/consume
(fn [e]
(println e))
connection)
;; sends data to websocket
(s/put! connection
"test string")
;; closes connection
(s/close! connection)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment