<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";
mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
span.E-MailFormatvorlage17
{mso-style-type:personal;
font-family:"Calibri","sans-serif";
color:windowtext;}
span.E-MailFormatvorlage18
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:70.85pt 70.85pt 2.0cm 70.85pt;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=DE link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='color:#1F497D'>Hi,<o:p></o:p></span></p><p class=MsoNormal><span style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'>I found a solution I think is appropriate. I wrote test-listener a little different just like what I need in my application:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'>(defun test-listener ()<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'> (loop <o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'> (let ((stream (ccl:accept-connection *test-socket*<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'> :stream-args '(:external-format :iso-8859-1))))<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'> (adt:record :dbg "connect test")<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'> (loop<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'> (handler-case<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'> (read-char stream)<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'> (error ()<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'> (return))))<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'> (adt:record :dbg "disconnect test"))))<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'>It seems my problem was lack of knowledge of TCP/IP internals. Did not know anything about sending FINs. Before closing the client connection I do<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'>(ccl:shutdown *<b>test-stream</b>* :direction :output)<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'>This causes read-char to produce an unexpected end of input error, which I catch in the handler-case. Perhaps not elegant but probably not to handle by other means.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'>Further suggestions welcome, but problem solved.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'>Andreas<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='color:#1F497D'><o:p> </o:p></span></p><div style='border:none;border-left:solid blue 1.5pt;padding:0cm 0cm 0cm 4.0pt'><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";mso-fareast-language:DE'>Von:</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";mso-fareast-language:DE'> Openmcl-devel [mailto:openmcl-devel-bounces@clozure.com] <b>Im Auftrag von </b>Andreas Thiele<br><b>Gesendet:</b> Montag, 30. November 2015 16:00<br><b>An:</b> openmcl-devel@clozure.com<br><b>Betreff:</b> [Openmcl-devel] How can I detect a client closed its connection to a listener socket?<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Hi,<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><span lang=EN-US>I wrote the following bit of code:<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>(defvar *test-socket* nil)<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>(defun test-listener ()<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US> (loop <o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US> (let ((stream (ccl:accept-connection *test-socket*<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US> :stream-args '(:external-format :iso-8859-1))))<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US> (adt:record :dbg "connect test")<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US> (loop :unless (ccl:stream-eofp stream) :do (sleep 0.2))<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US> (adt:record :dbg "disconnect test"))))<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>(defun start-test-listener ()<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US> (setf *test-socket* (ccl:make-socket :local-port 4010<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US> :connect :passive :reuse-address t :keepalive t))<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US> (ccl:process-run-function "Test Listener" 'test-listener))<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>(defvar *test-stream* nil)<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>(defun connect-test ()<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US> (ignore-errors<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US> (setf *test-stream* (ccl:make-socket :remote-host "127.0.0.1"<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US> :remote-port 4010))))<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>adt:record just prints to my slime-repl. I start the listener using start-test-listener connect a client via connect-test. “connect test” appears within my slime window. I do a (close *<b>test-stream</b>*) but nothing happens. (ccl:tream-eofp stream) never returns true and thus the loop never ends and no “disconnect test” can appear. Is there a way to solve this? How do I detect, the client has closed the connection?<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>Thankful for any hint or help.<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US>Best Regards<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US>Andreas Thiele<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p></div></div></body></html>