On Sun, 09 Mar 2014 09:56:10 GMT, hardcoder wrote:

On Sun, 09 Mar 2014 02:20:08 GMT, Stephan wrote:

On Fri, 07 Mar 2014 22:48:49 GMT, hardcoder wrote:

Hi,

I am evaluating Vibe.d for my next project. It will be used as a TCP and UDP server.

I just compiled basic TCP example but the momnet I wanted to do simple change things started to work unexpectedly.

In my simple example client app just writes bytes to socket and then starts reading.

Things work ok when handler looks like this:

void onConnection(TCPConnection conn)
{
  conn.write(conn);
}

but when I change it to:

void onConnection(TCPConnection conn)
{
  auto data = conn.readAll;
  conn.write(data);
}

handler never writes data back because readAll() blocks. In other thread I found the answer: realAll() blocks until client closes connection. Answer also suggests readLine() but in my case it wont work as data is binary.

My question: how to read InputStream the same way conn.write(conn) does in the first version?

Try Reading and writing in separate tasks - a bit like in this sample:

https://github.com/rejectedsoftware/vibe.d/blob/master/examples/tcp_separate/source/app.d

That way you don't need to wait until all data came in. Reading can be done in chunks then

Sorry but I don't see how reading in different task changes semantics or readAll().

Well you simply do not want to use readAll when you want to pipe chunks of incoming data to another stream.
use read() for reading (and waiting) for chunks of data until the stream end is reached. yes read will block in this case too, but that does not matter, because of the concept of tasks. it is just that one task that gets blocked.
if you even don't want to chunk it and send every byte as it arrives, you can use waitForData which blocks until any data arrives and ask how much of a chunk actually did arrive using leastSize.