eio
eio copied to clipboard
Multiple message in TCP communication with flow
Hello there,
I was trying to build a TCP server to handle some client requests, I followed example in the README, it works.
But when I make multiple messages in one connection directly with flow, both sides got blocked. What I did is
Server: flow.read_all
for reading then use flow.copy_string
for writing.
Client: flow.copy_string
for writing then flow.read_all
for reading
My guess is that the data is client data is not send to the server, but buffered somehow, so server get blocked by the read_all
, so the client get blocked by the second read_all
. The example in the README works, because the server fibre closed, so the data get to flushed to the client.
Later, I switch to Buf_read
and Buf_write
to explicitely indicate what to write and to read, add line break to my string message and use Buf_read.line
to read data from flow. This works, I can send multiple messages.
I am wondering if I use it correctly, because I don't have too much network programming experience before. If it is, maybe it is a good example to put into the README. I can do the honour if needed.
Best
read_all
has to wait until the connection is shut down in order to read all the data. Could that be the problem?
read_all
has to wait until the connection is shut down in order to read all the data. Could that be the problem?
Yes, this is the problem, I was looking for something simple like Unix.flush
.
Thanks for the explanation !