cch1 / http.async.client

Async Http Client - Clojure
http://cch1.github.com/http.async.client
267 stars 40 forks source link

README.org websocket example could be improved #71

Closed paneadie closed 8 years ago

paneadie commented 8 years ago

Perhaps a newbie issue, but might help others..

I had some issues using the example as the websocket, it was connecting fine, but it did not appear to be handling messages. It looks to me like this example should also include :text

Looking at the code in websocket.clj it does appear to have two distinct methods for handing char vs byte, create-text-listener and create-byte-listener

I just re-used handle-message, added in :text handle-message

eg: (existing)

  (defn -main []
  (println "Connecting...")
  (with-open [client (http/create-client)]
    (let [ws (http/websocket client
                             url
                             :open  on-open
                             :close on-close
                             :error on-error
                             :byte  handle-message)]
      ; this loop-recur is here as a placeholder to keep the process
      ; from ending, so that the message-handling function will continue to
      ; print messages to STDOUT until Ctrl-C is pressed
      (loop [] (recur)))))
  (defn -main []
  (println "Connecting...")
  (with-open [client (http/create-client)]
    (let [ws (http/websocket client
                             url
                             :open  on-open
                             :close on-close
                             :error on-error
                             :byte  handle-message
                             :text handle-message)]
      ; this loop-recur is here as a placeholder to keep the process
      ; from ending, so that the message-handling function will continue to
      ; print messages to STDOUT until Ctrl-C is pressed
      (loop [] (recur)))))
paneadie commented 8 years ago

Closed as part of commit https://github.com/cch1/http.async.client/commit/0d43a11de7c1ea905fcad0d57ed0138e06dd9ae2