6

I have the following code:

(ns alephtest.core             
    (:use lamina.core aleph.tcp aleph.formats))

(defn connection-established [socket] 
    (println "Socket connection established")
    (on-closed socket #(println "closed"))
    (doseq [line (line-seq (java.io.BufferedReader. *in*))]
        (enqueue socket line)))

(defn -main [] 
    (on-realized (tcp-client {:host "localhost" :port 9000}) 
        connection-established 
        #(println "error:" %)))

All it does right now is connects to a local server and then passes data from stdin through to the server. This works fine, except for the (on-closed socket #(println "closed")) portion. If I kill the server while the client is still going I should get a message saying "closed" to the console, but I never do.

My end-goal here is to create some kind of recovery code, so that if the server goes down the client will queue up messages while it waits for the server to come back, and when the server does come back it'll reconnect and send everything that was queued.

4

1 回答 1

7

看起来您正在阻塞会通知您套接字关闭的线程(doseq ...)。把它包起来(future ...),看看是否不能解决它。

于 2012-11-11T02:06:07.877 回答