<html>
<head>
<meta content="text/html; charset=windows-1252"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
On 09/03/2014 12:01 PM, Gilbert Martinez wrote:<br>
<blockquote
cite="mid:CAOyHz4vWHwGqeyJ7PBGXHskGb24dP1O4M0H-WauiSEaDtQ5qpg@mail.gmail.com"
type="cite">
<div dir="ltr">I'm having issues reading the response from a TCP
server. Specifically, any attempt to read the input port does
not terminate. I've used <font face="courier new, monospace">port->bytes</font>,
<font face="courier new, monospace">read-byte</font>, and <font
face="courier new, monospace">read-line.</font> In all cases
the effect is the same.
<div>
<br>
</div>
<div>I thought that if there were no bytes available on an input
port that the read attempt would just return <eof>. Is
this some kind of exclusivity issue? Can I not read from the
port until the connection with the server is closed or
something?<br>
</div>
</div>
</blockquote>
This is not true. Most functions like 'read-byte' block until there
are bytes available to read. You don't get <eof> until the
port (connection) is closed. If you want a non-blocking call, look
at 'read-bytes-avail!*'.<br>
<br>
<tt>#lang racket</tt><tt><br>
</tt><tt><br>
</tt><tt>(define-values (in out) (make-pipe))</tt><tt><br>
</tt><tt><br>
</tt><tt>(thread</tt><tt><br>
</tt><tt> (lambda ()</tt><tt><br>
</tt><tt> (for ((i 5))</tt><tt><br>
</tt><tt> (write-byte i out)</tt><tt><br>
</tt><tt> (sleep 1))</tt><tt><br>
</tt><tt> (close-output-port out)))</tt><tt><br>
</tt><tt><br>
</tt><tt>(for ((b in))</tt><tt><br>
</tt><tt> (printf "~x " b))</tt><br>
<br>
'for' is pretty smart in my experience. I believe in this case it's
using a sequence from 'in-port'. But in any case, you should see
numbers print out before the port is closed.<br>
<br>
Does this help?<br>
<br>
Thanks,<br>
Dave<br>
</body>
</html>