Hi,
I want to have a server and a client that do not close connection when doing request/response rounds. However, I can't convince my client to flush the output and send data without closing a connection. This is the code:
client.d
auto conn = connectTcp("127.0.0.1", 1234);
string text;
while(1)
{
  text = stdin.readln();
  if (text == "exit") break;
 
  conn.write(text, true);
}
I have tried the write with and without the flush parameter. Also setting conn.tcpNoDelay = true. None of this works. conn must be closed for the data to be sent. Confirmed with wireshark. What to do?
Also, how should a propper server that listens for such persistent connections look like? So far I have this, but it does not seem right. Especially the part with waitForData...
server.d
listenTcp(1234, (conn)
{
  ubyte[] data;
  auto part = appender!(ubyte[])();
  while (conn.connected)
  {
    if (!conn.waitForData(dur!"msecs"(250))) continue;
    while (!conn.empty)
    {
      size_t chunk = cast(size_t)min(conn.leastSize, BUFFER_SIZE);
      conn.read(_buffer[0..chunk]);
      part.put(_buffer[0..chunk]);
    }
    data ~= part.data;
    ...
    // Fiddle with data
    ...
  }
});
Thanks,
Martin