Skip to content

Instantly share code, notes, and snippets.

@dom96
Created April 6, 2014 19:07
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 dom96/10010212 to your computer and use it in GitHub Desktop.
Save dom96/10010212 to your computer and use it in GitHub Desktop.
import asyncnet, asyncdispatch
var clients: seq[PAsyncSocket] = @[]
proc processClient(client: PAsyncSocket) {.async.} =
while true:
let line = await client.recvLine()
for c in clients:
await c.send(line & "\c\L")
proc serve() {.async.} =
var server = newAsyncSocket()
server.bindAddr(TPort(12345))
server.listen()
while true:
let client = await server.accept()
clients.add client
processClient(client)
serve()
runForever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment