Crystal: tcp_server and tcp_client sample code not working properly

Created on 4 May 2017  路  4Comments  路  Source: crystal-lang/crystal

When I run the sample programs "crystal tcp_server.cr" and then "crystal tcp_client.cr" The server receives the first message from the client, but the client hangs when attempting to read the response from the server. I've modified the tcp_server.cr so that the programs operate as what I believe should be expected, however there probably is a better way to do it than I have as I've just begun learning Crystal and have only limited Ruby experience. Here is the modified file. I am using Crystal 0.22 with Ubuntu 16.04.2 LTS.

Most helpful comment

@straight-shoota Nope, it was changed in 0.20.3, see #3704.

All 4 comments

@wjmacfarland thanks for reporting, I fixed by using IO#puts so the newline character is added and the tcp_client will read until it when doing the IO#gets.

Shouldn't IO#read_line (i.e. IO#gets) return the message with the terminating newline character included?

@straight-shoota Nope, it was changed in 0.20.3, see #3704.

Oh, thanks! Seems like I missed that change...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Sija picture Sija  路  3Comments

grosser picture grosser  路  3Comments

oprypin picture oprypin  路  3Comments

costajob picture costajob  路  3Comments

lbguilherme picture lbguilherme  路  3Comments