Clojure WebSocket Client

前端 未结 6 822
死守一世寂寞
死守一世寂寞 2021-02-07 05:40

I have set up a WebSocket server using http-kit that should accept web socket connections. It is the basic example shown in the http-kit documentation.

The quest

6条回答
  •  时光说笑
    2021-02-07 06:21

    According to this announcement, http-kit has support for web sockets. If you're not bound to the asynchronous facilities that http-kit client offer, you could also use clj-http. They have a very similar interface, it seems (I have use but clj-http yet).


    (ns playground.experiments.ws
      (:use aleph.http lamina.core))
    
    (defn ws-client [] (websocket-client {:url "ws://echo.websocket.org:80"}))
    
    (defn echo [message]
      (let [channel (wait-for-result (ws-client) 500)]
        (enqueue channel message)
          (let [echo (wait-for-result (read-channel channel) 500)]
            (close channel)
            echo)))
    
    (echo "Echo me!")
    

提交回复
热议问题