-
-
Save adam12/83720a8845530f616c29 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 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