Hello
I have a test app programmed by newlisp. It connects to the server via TCP first, never sends request to server until server close the connection when timeout.
I read the API doc, but don't know which API could help me to determine the current connection's status.
Should I call net-send or net-receive for it?
How to know the TCP connection was closed?
-
- Posts: 107
- Joined: Tue Jan 15, 2013 11:54 am
- Location: China, Beijing
- Contact:
How to know the TCP connection was closed?
Last edited by csfreebird on Thu Jan 24, 2013 11:49 am, edited 1 time in total.
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
Re: How to know the TCP connectio was closed?
Is net-peek any use?
-
- Posts: 107
- Joined: Tue Jan 15, 2013 11:54 am
- Location: China, Beijing
- Contact:
Re: How to know the TCP connectio was closed?
net-receive works for me.
But net-peek doesn't. It returns 0 instead of nil when connection has been closed by server.
Code: Select all
(if (net-receive s buffer 2) (println "failed, the connection should be closed, time:" (date (date-value))) (println "succeeded, the connection was closed:" (net-error)))
Code: Select all
(println (net-peek s))
(if (= (net-peek s) nil) (println "succeeded, the connection was closed:" (net-error)))
-
- Posts: 107
- Joined: Tue Jan 15, 2013 11:54 am
- Location: China, Beijing
- Contact:
Re: How to know the TCP connectio was closed?
I tried your suggestion. It works for me. Thank you.
Below is my two functions for this topic, hope it would be helpful for others.
But why the (net-select s "exception" 1000) returns nil when connection was closed.
It seems it should return true to tell users there is an exception happened.
Below is my two functions for this topic, hope it would be helpful for others.
Code: Select all
;; return true if connection was closed
(define (net-close2? s)
(if (net-receive s buffer 2) nil true))
(define (net-close? s)
(if (net-select s "exception" 1000) nil true))
It seems it should return true to tell users there is an exception happened.