[plt-scheme] TCP example not working
On Oct 10, Veer wrote:
> The example below is given in the guide hangs around (read-line s-in) .
>
> (define server (tcp-listen 12345))
> (define-values (c-in c-out) (tcp-connect "localhost" 12345))
> (define-values (s-in s-out) (tcp-accept server))
> (display "hello\n" c-out)
> (read-line s-in)
> (close-output-port c-out)
> (read-line s-in)
You're right -- the problem is that nothing actually goes out on the
connection because it is buffered. One way to make it work is to add
(flush-output c-out)
after the `display' line, and another is to move
(close-output-port c-out)
one line up to before the `read-line' (because closing the port also
flushes it).
I committed the last change to the guide.
--
((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay:
http://www.barzilay.org/ Maze is Life!