Advertisement
Guest User

Untitled

a guest
Jul 1st, 2014
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (def clients (atom #{}))
  2.  
  3. (defn ws-handler [req]
  4.   (http-kit/with-channel req channel
  5.                 (println channel "connected")
  6.                 (swap! clients conj channel)
  7.                 (http-kit/on-receive channel (fn [_] (println "received")))
  8.                 (http-kit/on-close channel (fn [status]
  9.                                              (println "clients" clients)
  10.                                     (swap! clients disj channel)
  11.                                     (println channel "closed, status" status)))))
  12.  
  13. (defroutes ws-routes
  14.            (GET "/ws" [] ws-handler))
  15.  
  16. ;cljs code
  17. (enable-console-print!)
  18.  
  19. (def conn
  20.   (js/WebSocket. "ws://127.0.0.1:3000/ws"))
  21.  
  22. (defn ^:export init []
  23.   (set! (.-onopen conn)
  24.         (fn [e] (.log js/console "opeiaeiaen")))
  25.   (set! (.-onerror conn)
  26.         (fn [e] (println "error: " e)))
  27.   (set! (.-onmessage conn)
  28.         (fn [e] (println "message"))))
  29.  
  30. ;error
  31. 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