Skip to content

Instantly share code, notes, and snippets.

@recoilme
Created December 19, 2016 17:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save recoilme/08d8ff4e5cfdb5fd1b2635d67334fd7c to your computer and use it in GitHub Desktop.
Save recoilme/08d8ff4e5cfdb5fd1b2635d67334fd7c to your computer and use it in GitHub Desktop.
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