Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (def clients (atom #{}))
- (defn ws-handler [req]
- (http-kit/with-channel req channel
- (println channel "connected")
- (swap! clients conj channel)
- (http-kit/on-receive channel (fn [_] (println "received")))
- (http-kit/on-close channel (fn [status]
- (println "clients" clients)
- (swap! clients disj channel)
- (println channel "closed, status" status)))))
- (defroutes ws-routes
- (GET "/ws" [] ws-handler))
- ;cljs code
- (enable-console-print!)
- (def conn
- (js/WebSocket. "ws://127.0.0.1:3000/ws"))
- (defn ^:export init []
- (set! (.-onopen conn)
- (fn [e] (.log js/console "opeiaeiaen")))
- (set! (.-onerror conn)
- (fn [e] (println "error: " e)))
- (set! (.-onmessage conn)
- (fn [e] (println "message"))))
- ;error
- WebSocket connection to 'ws://127.0.0.1:3000/ws' failed: Error during WebSocket handshake: Unexpected response code: 500
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement