Why doesn't the Aleph HTTP server do anything?

I wrote a relatively simple HTTP server using the Clojure Aleph library. This is not very difficult:

(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, this is quite simple, and pretty closely follows the example given in the Aleph document. It compiles fine, but when I run it (via lein run ), it just ... does nothing. The program ends immediately; obviously he is not listening on port 8005 or something like that. What am I missing here? Obviously, there must be something else I need to do to start the server in Aleph.

+5
source share
2 answers

You want to call "aleph.netty / wait-for-close" on the value returned by "start-server" to lock until the server closes.

+10
source

http / start-server is not blocked, it simply returns an object, so you don’t need to do anything else to fulfill the main goals and complete the program.

I do not use aleph and do not see the obvious join pattern. It seems like you need to do one of your own lifecycle management and then call .close on the object returned from the start server to gracefully close.

+5
source

All Articles