eio icon indicating copy to clipboard operation
eio copied to clipboard

Multiple message in TCP communication with flow

Open Wenke-D opened this issue 5 months ago • 2 comments

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

Wenke-D avatar Mar 21 '24 09:03 Wenke-D

read_all has to wait until the connection is shut down in order to read all the data. Could that be the problem?

talex5 avatar Mar 21 '24 15:03 talex5

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.

Wenke-D avatar Mar 21 '24 15:03 Wenke-D

Thanks for the explanation !

Wenke-D avatar Mar 23 '24 11:03 Wenke-D