Skip to content

Instantly share code, notes, and snippets.

@djui
Forked from jbochi/listener.clj
Created May 10, 2014 07:07
Show Gist options
  • Save djui/953bd39f404f85184d6e to your computer and use it in GitHub Desktop.
Save djui/953bd39f404f85184d6e to your computer and use it in GitHub Desktop.
(require '[com.keminglabs.zmq-async.core :refer [register-socket!]]
'[clojure.core.async :refer [>! <! <!! >!! go chan sliding-buffer close!]])
(let [addr "tcp://*:9999"
[s-in s-out] (repeatedly 2 #(chan (sliding-buffer 64)))]
(register-socket! {:in s-in :out s-out :socket-type :rep
:configurator (fn [socket] (.bind socket addr))})
(println "waiting messages...")
(while true
(println (String. (<!! s-out)))
(go (>! s-in "OK"))))
(require '[com.keminglabs.zmq-async.core :refer [register-socket!]]
'[clojure.core.async :refer [>! <! <!! >!! go chan sliding-buffer close!]])
(let [addr "tcp://localhost:9999"
[s-in s-out] (repeatedly 2 #(chan (sliding-buffer 64)))]
(register-socket! {:in s-in :out s-out :socket-type :req
:configurator (fn [socket] (.connect socket addr))})
(println "type to send..")
(while true
(>!! s-in (read-line))
(go (println (String. (<! s-out))))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment