Clojure 如何在Aleph中处理websocket断开连接(从页面重新加载)?
我已经使用aleph编写了一个基于事件的websocket处理程序。核心文件如下所示:Clojure 如何在Aleph中处理websocket断开连接(从页面重新加载)?,clojure,websocket,Clojure,Websocket,我已经使用aleph编写了一个基于事件的websocket处理程序。核心文件如下所示: (defn handle-message "Handle a message" [message] (event/dispatch message)) (defn websocket-handler "Handle websocket connections." [client-node connection-data] (map* #(handle-message (message
(defn handle-message
"Handle a message"
[message]
(event/dispatch message))
(defn websocket-handler
"Handle websocket connections."
[client-node connection-data]
(map* #(handle-message (message/create client-node connection-data %)) client-node))
(defn -main
"Start the http server and start handling websocket connections."
[& args]
(myapp.routes.api/add-events)
(start-http-server websocket-handler {:port 8080 :websocket true}))
这很好,我有一些事件可以工作并给出预期的输出。当我重新加载页面时,它停止工作。有什么问题吗?我假设发生了断开/重新连接。如何管理服务器端的断开连接?在客户端连接功能中,添加一个fn,以处理通道端关闭时的操作:
(defn connection-handler [channel request]
(lamina/on-closed channel handle-client-disconnected-fn)
)
(defroutes my-routes
(GET "/my-website-path" [] (wrap-aleph-handler connection-handler))
)
(start-http-server
(->
my-routes
(wrap-session)
(wrap-file "./public")
(wrap-file-info)
(wrap-stacktrace)
(wrap-ring-handler)
)
{:port 8080 :websocket true}
)
编辑:在实践中,检查它们是否尚未连接,以便您不会多次添加处理程序什么是事件/调度?