Reputation: 410732
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.
Upvotes: 5
Views: 601
Reputation: 776
You'll want to call 'aleph.netty/wait-for-close' on the value returned by 'start-server' to block until the server is closed.
Upvotes: 11
Reputation: 3708
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.
Upvotes: 5