On Wed, 21 Aug 2013 19:23:48 GMT, Jack Applegame wrote:

Strange. This example crashes (Windows 7 64bit, dmd 2.063.2, driver: libevent):

From a quick look, I didn't figure out why it crashes, but the reason why it doesn't work is that the task that calls the delegate passed to listenTCP will close the connection once that delegate returns. The proper fix would be to wait for the manually started task to finish. Modified source with a join() call added:

import vibe.d;

shared static this() {
    runTask({
        sleep(1.seconds);
        listenTCP(8000, (conn){
            accept(conn);
        }, "127.0.0.1");
        auto conn = connectTCP("127.0.0.1", 8000);
        logInfo("client: connected");
        conn.write("client: hello");
        logInfo("client: sent");
        ubyte[13] buf;
        conn.read(buf);
        logInfo("client: received '%s'", cast(string)buf);
    });
}
void accept(TCPConnection conn) {
    // Trying send and receive in new task
    runTask({
        conn.write("server: hello");
        logInfo("server: sent");
        logInfo("server: accepted");
        ubyte[13] buf;
        conn.read(buf);
        logInfo("server: received '%s'", cast(string)buf);
    }).join();
}