[racket] tcp exceptions and connection reestablishment...

From: Rüdiger Asche (rac at ruediger-asche.de)
Date: Wed Jun 20 09:21:36 EDT 2012

I'm struggling with exception processing in a particular case - I'm  
sure this is a trivial question with a trivial answer, but for some  
reason (most probably stupidity on my part) I haven't found an answer  
yet, so here goes:

I have an application that implements a communication protocol over  
the network, ie

(letrec-values [((inport outport) (tcp-connect somehostname somehostport))
                 ((protocolfn (lambda ()
                   ....
                  (read-something inport)
                   ....
                  (write-something outport))]
     (protocolfn))

or respectively on the server side

(letrec-values [((inport outport) (tcp-accept (tcp-listen somehostport)))
                 ((protocolfn (lambda ()
                  ....
                  (read-something inport)
                  ....
                  (write-something outport))]
     (protocolfn))

This compiles and runs just fine. However when either side closes the  
connection, a TCP exception is raised that throws me out of the  
application (or to the REPL in interactive mode).

I have tried call-with-exception-handler and handlers in different  
variations but haven't been able to produce code that allows me to  
gracefully return to reestablishing the connection. Does anyone have a  
code snippet that helps me?

Thanks as usual!






Posted on the users mailing list.