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