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

From: Robby Findler (robby at cs.uchicago.edu)
Date: Tue Aug 5 08:48:35 EDT 2003

[ this email didn't make it to the list the first or second time,
  here's attempt 3 ]

I think that the read isn't sure that there are more characters coming.
For some sexpressions, like this one:

  (abc)

read can tell that the expression is done without any extra chars. For
this expression:

  ping

read does not know if there are more characters coming in the port.

Try adding this on the client side:

  (newline me->server)

after the ping is written to the port.

Robby

At Thu, 31 Jul 2003 23:30:54 -0700, briand at aracnet.com wrote:
> 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))))
> 







Posted on the users mailing list.