I've written a relatively simple HTTP server using Clojure's Aleph library. It's not very complicated:
(ns cxpond.xmlrpc.core
(:gen-class)
(:require [aleph.http :as http]))
(defn handler [req]
{:status 200
:headers {"Content-Type" "text/plain"}
:body "HELLO, WORLD!"})
(defn -main [& args]
(http/start-server service/handler {:port 8005}))
Obviously it's pretty simple, and follows the example given in Aleph's doc pretty closely. It compiles fine, but when I run it (via lein run
) it just...does nothing. The program just exits immediately; obviously it doesn't listen on port 8005 or anything like that. What am I missing here? Clearly there must be something else I need to do to start a server in Aleph.
You'll want to call 'aleph.netty/wait-for-close' on the value returned by 'start-server' to block until the server is closed.
http/start-server doesn't block, just returns an object, so with nothing else to do execution of -main finishes and the program ends.
I don't use aleph and don't see an obvious join-like pattern. It looks as though one has to do one's own lifecycle management, then call .close on the object returned from start-server to gracefully shut down.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With