Created
December 19, 2016 17:30
-
-
Save recoilme/08d8ff4e5cfdb5fd1b2635d67334fd7c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import reactor/tcp, reactor/loop, reactor/async, reactor/util, reactor/ipaddress, reactor/time | |
proc processClient(client: TcpConnection) {.async.} = | |
var die = false | |
while true: | |
let recvData = await client.input.readLine(255) | |
echo repr(recvData) | |
echo recvData | |
if recvData == "\13\10": | |
echo "end" | |
break | |
if recvData == "": | |
echo "end2" | |
break | |
#[] | |
let line = await client.recvLine() | |
if line=="" or line=="quit": | |
echo "terminate" | |
client.close() | |
for i,cl in clients: | |
if cl == client: | |
clients.delete(i) | |
break | |
break | |
await client.send(content)]# | |
proc main() {.async.} = | |
let srv = await createTcpServer(12345) | |
await asyncSleep(100) | |
#let conn = await connectTcp("localhost", 6669) | |
echo "ok" | |
while true: | |
echo "in loop" | |
let client = await srv.incomingConnections.receive() | |
discard processClient(client) | |
#let data = "hello world\n" | |
#await conn.output.write(data) | |
#let recvData = await client.input.readLine(100) | |
#echo recvData | |
echo "out loop" | |
main().runLoop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment