Skip to content

Instantly share code, notes, and snippets.

@adam12
Created January 22, 2015 03:50
Show Gist options
  • Save adam12/83720a8845530f616c29 to your computer and use it in GitHub Desktop.
Save adam12/83720a8845530f616c29 to your computer and use it in GitHub Desktop.
import asyncnet, asyncdispatch
var clients {.threadvar.}: seq[AsyncSocket]
proc processClient(client: AsyncSocket) {.async.} =
while true:
let line = await client.recvLine()
for c in clients:
await c.send(line & "\c\L")
proc serve() {.async.} =
clients = @[]
var server = newAsyncSocket()
server.bindAddr(Port(12345))
server.listen()
while true:
let client = await server.accept()
clients.add client
asyncCheck processClient(client)
asyncCheck serve()
runForever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment