Created
November 8, 2012 16:07
-
-
Save daviesian/4039751 to your computer and use it in GitHub Desktop.
Aleph Server and Client stuff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns meta-ex-client.core | |
(:use compojure.core | |
compojure.route | |
aleph.tcp | |
gloss.core | |
lamina.core | |
clojure.data.json | |
clojure.pprint)) | |
(def client (tcp-client {:host "localhost", :port 9901, :frame (string :utf-8 :delimiters ["\n"])})) | |
(let [out *out*] | |
(receive-all @client (fn [msg] | |
(binding [*out* out] | |
(println msg))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns meta-ex-server.core | |
(:use compojure.core | |
compojure.route | |
aleph.http | |
aleph.tcp | |
lamina.core | |
clojure.data.json | |
clojure.pprint | |
gloss.core | |
)) | |
(def overtone-pool (atom #{})) | |
(defn play-thing [id] | |
(doseq [ch @overtone-pool] | |
(enqueue ch (str "Play thing! " id))) | |
(println "Playing thing.")) | |
(let [my-out *out*] | |
(defroutes svr-routes | |
(GET "/test" [] | |
"<a href=\"/play-thing/7\">Play something!</a>") | |
(GET "/play-thing/:id" [id] | |
(binding [*out* my-out] | |
(play-thing id)) | |
(ring.util.response/redirect "/test")) | |
(not-found "Page not found."))) | |
(defonce svr (start-http-server (wrap-ring-handler #(#'svr-routes %)) {:port 8800})) | |
(defn tcp-handler [ch client-info] | |
(swap! overtone-pool conj ch) | |
(on-closed ch #(swap! overtone-pool disj ch))) | |
(def tcp-svr (start-tcp-server #(#'tcp-handler %1 %2) {:port 9901 :frame (string :utf-8 :delimiters ["\n"])})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment