A minimal (< 500 SLOC) websocket client in clojure - without any dependencies.
Passes the autobahn websockets testsuite (see results).
(require '[yawc.core :as yawc])
(let [client (yawc/open
{:host "echo.websocket.org"
:port 80
:path "/"
:cb (fn [type payload client]
(cond
(#{:text :close :connect} type) (println type payload)
:else (println type (String. payload))))})]
;; => :connect {:status 101, :reason Web Socket Protocol Handshake, :headers {connection Upgrade, date Sun, 01 Apr 2018 13, sec-websocket-accept g7Uq6gHNVaVhx/pERAJiHxDSs/w=, server Kaazing Gateway, upgrade websocket}, :content }
(yawc/emit client {:opcode 1 :payload (.getBytes "Hello World!")}))
;; => :text Hello World!
- improve performance
- do bit operations in java rather than clojure https://github.com/phillord/primitive-operator