我使用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中启动服务器时,我需要做一些其他工作.
http/start-server不会阻塞,只返回一个对象,所以没有其他任何东西可以执行-main完成并且程序结束.
我不使用aleph,也没有看到明显的连接模式.看起来好像必须进行一个人自己的生命周期管理,然后对从start-server返回的对象调用.close来正常关闭.
| 归档时间: |
|
| 查看次数: |
360 次 |
| 最近记录: |