I've written a very simple broadcast/echo server that uses web sockets with clojure and aleph.
I spent a lot of time looking through the aleph and lamina sources to get a decent, basic understand what's happening here.
What I want to do
- Establish connections from clients
- Send occasional instructions to the server
- The instructions are executed and a response is sent to others based on some meta-data about the connection
So this can process the data (which is great) and format the response (which is great). How can I get it to send the response only to relevant parties?
What I have so far
(defn do-something
[arg]
(str "pickles" "are" "nice" arg))
(defn ws-handler [ch request]
(siphon (map* #(do-something %) ch) broadcast-channel)
(siphon broadcast-channel ch))
(defn -main
"Start the http server"
[& args]
(start-http-server ws-handler {:port 8080 :websocket true}))
Example Request
Let's say I had this request in JSON:
{"room":32, "color":"red", "command":"do something..."}
I would want this to execute the "do something..." command, then the resultant output would be sent to everyone else whose most recent command had included {"room":32, "color":"red"}.
I don't understand how to manage connections this way in aleph... any help?