Discussion:
Detect when tcp connection is closed?
Dan Johansson
2015-05-27 10:39:56 UTC
Permalink
Hi
I'm trying to detect when the remote end closes the tcp connection as shown
in the 2 code examples below.
When using aleph 0.3.x and lamina the client connection report that it is
closed as soon as the server closes.
When using aleph 0.4.x I need to send a few puts before the stream says it
is disconnected.

Note: The client fn is as defined in *aleph.examples.tcp*

How do I best detect that the server closed the connection?

Thanks
Dan


(def st1 (start-server ctrl-handler 8286))
(def c1 @(client "localhost" 8286))
*(s/closed? c1) -> false*
*(.close st1)*
*(s/closed? c1) -> false*
*(while @(s/put! c1 "test"))*
*(s/closed? c1) -> true*

(def ts1 (tcp/start-tcp-server ctrl-handler {:port 8585, :frame
(gloss/string :utf-8 :delimiters ["\r\n"])}))

(def tch1 (lamina/wait-for-result
(tcp/tcp-client {:host "localhost",
:port 8585,
:frame (gloss/string :utf-8 :delimiters ["\r\n"])})))

*(lamina/closed? tch1) -> false*
*@(ts1)*

*(lamina/closed? tch1) -> true*
--
You received this message because you are subscribed to the Google Groups "Aleph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to aleph-lib+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...