[plt-scheme] closing tcp port needed to read ??

From: briand at aracnet.com (briand at aracnet.com)
Date: Fri Aug 1 02:30:54 EDT 2003

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 ???


(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) 
      (let ([response (read server->me)])
        (display response) 
      (close-input-port server->me))))

Posted on the users mailing list.