Here's a pattern that hopefully satisfies your needs: 
    
    
    import asyncnet, asyncdispatch
    
    proc doStuff(): Future[string] =
        var retFut = newFuture[string]("asynctest.doStuff")
        
        var server = newAsyncSocket()
        server.bindAddr(Port(12345))
        server.listen()
        
        let clientFut = server.accept()
        clientFut.callback = proc() =
            let lineFut = clientFut.read.recvLine()
            lineFut.callback = proc() =
                retFut.complete(lineFut.read)
                server.close()
        
        result = retFut
    
    let msg = waitFor(doStuff())
    echo "message: ", msg
    

And here's a client that you can test it with: 
    
    
    import asyncnet, asyncdispatch
    
    let client = newAsyncSocket()
    waitFor client.connect("127.0.0.1", 12345.Port)
    waitFor client.send("HELLO" & "\c\L")
    

Is it actually supposed to be a server rather than a client?

Reply via email to