[plt-scheme] Re: plt-scheme digest, Vol 1 #465 - 4 msgs

From: Keith Frost (keithf at amnis.com)
Date: Fri Aug 1 12:43:22 EDT 2003

Try (flush-output me->server) instead of (close-output-port me->server).
(newline me->server) might also work.   I think that the behavior you 
report
is because output is being buffered, so you need to force it to get flushed.

>Message: 4
>Date: Thu, 31 Jul 2003 23:30:54 -0700
>To: plt-scheme at list.cs.brown.edu
>From: briand at aracnet.com
>Subject: [plt-scheme] closing tcp port needed to read ??
>
>See code and end of e-mail.
>
>Seems very straightforward.  Run server, run client they talk.
>
>Here's the part I don't understand.
>
>If I remove the 
>
>       (close-output-port me->server)
>
>which occurs after the (write 'ping ...) in client, then the client
>can't read the from the server !
>
>I can't figure this out at all.  Nothing in the doc's seem to give me
>any hints.  The ports are separate, right ?  Why would you have to
>close the client's output port in order for the client to be able to
>read from the server ???
>
>
>Brian
>
>
>(define server
>  (lambda ()
>    (let ((listener (tcp-listen port)))
>      (printf "Listening ~a~n" listener)
>      (let-values (((client->me me->client)
>                    (tcp-accept listener)))
>		  (when (eq? (read client->me) 'ping)
>                    (write 'pong me->client)
>                    (newline me->client)
>                    (write 'who-are-you? me->client)
>                    (newline me->client))
>		  (close-output-port me->client)
>		  (close-input-port client->me)))))
>
>(define client
>  (lambda ()
>    (printf "Attempting connection ~a:~a~n" server-addr port)
>    (let-values (((server->me me->server)
>                  (tcp-connect server-addr port)))
>      (printf "Connected...~n")
>      (write 'ping me->server)
>      (close-output-port me->server)
>      (let ([response (read server->me)])
>        (display response) 
>        (newline))
>      (let ([response (read server->me)])
>        (display response) 
>        (newline))
>      (close-input-port server->me))))
>
>
>
>End of plt-scheme Digest
>
>  
>




Posted on the users mailing list.