为什么Aleph的HTTP服务器不做任何事情?

mip*_*adi 5 clojure aleph

我使用Clojure的Aleph库编写了一个相对简单的HTTP服务器.这不是很复杂:

(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}))
Run Code Online (Sandbox Code Playgroud)

显然它非常简单,并且非常接近Aleph的文档中给出的示例.编译很好,但是当我运行它(通过lein run)它只是......什么都不做.该计划立即退出; 显然它不会听8005端口或类似的东西.我在这里错过了什么?显然,在Aleph中启动服务器时,我需要做一些其他工作.

小智 11

你需要在'start-server'返回的值上调用'aleph.netty/wait-for-close'来阻止,直到服务器关闭.


Jon*_*ton 5

http/start-server不会阻塞,只返回一个对象,所以没有其他任何东西可以执行-main完成并且程序结束.

我不使用aleph,也没有看到明显的连接模式.看起来好像必须进行一个人自己的生命周期管理,然后对从start-server返回的对象调用.close来正常关闭.