Re: [racket-users] Racket Echo Server/Client hanging

2017-12-05 Thread Vishal Prasad
Jon,

Thanks!

-Vishal

On Wednesday, December 6, 2017 at 12:19:07 AM UTC-5, Jon Zeppieri wrote:
>
>
>
> On Wed, Dec 6, 2017 at 12:13 AM, Vishal Prasad  > wrote:
>
>> And this is the client:
>>
>>
>> (define (hello_socket port)
>> (define-values (in out) (tcp-connect "localhost" port))
>> (write "hello socket world\n" out)
>> (display (read in)))
>>
>>
>> The client does not receive any text back, and just hangs on the read. 
>>
>>
>> The `write` is buffered. If you add a `(flush-output out)`, it will work.
>
> - Jon 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] Racket Echo Server/Client hanging

2017-12-05 Thread Jon Zeppieri
On Wed, Dec 6, 2017 at 12:13 AM, Vishal Prasad  wrote:

> And this is the client:
>
>
> (define (hello_socket port)
> (define-values (in out) (tcp-connect "localhost" port))
> (write "hello socket world\n" out)
> (display (read in)))
>
>
> The client does not receive any text back, and just hangs on the read.
>
>
> The `write` is buffered. If you add a `(flush-output out)`, it will work.

- Jon

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] Racket Echo Server/Client hanging

2017-12-05 Thread Vishal Prasad
 

Really embarrassed I can't figure out what's going on here, but I just 
spent the last two hours banging my head against this going nowhere.


I'm trying to create a simple echo server and client in Racket.


This is the server:


(define (hello_listen port)
(define listener (tcp-listen port))
(define (loop)
(define-values (in out) (tcp-accept listener))
(thread (lambda ()
(copy-port in out)
(close-output-port out)))
(loop))
(loop))


And this is the client:


(define (hello_socket port)
(define-values (in out) (tcp-connect "localhost" port))
(write "hello socket world\n" out)
(display (read in)))


The client does not receive any text back, and just hangs on the read. 

When I write a simple client in Python however, the behavior is fine:


>>> import socket
>>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> s.connect(('localhost', ))
>>> s.send("hi")   
2
>>> s.recv(500)
'hi' 

What am I missing here in the Racket client code?

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.