Chat server: Difference between revisions

m
Line 1,162:
<lang nimrod>import asyncnet, asyncdispatch
 
type TClient = tuple[socket: PAsyncSocketAsyncSocket, name: string]
var clients: seq[TClientClient] = @[]
 
proc sendOthers(client: TClientClient, line: string) {.async.} =
for c in clients:
if c != client:
await c.socket.send(line & "\c\L")
 
proc processClient(socket: PAsyncSocketAsyncSocket) {.async.} =
await socket.send("Please enter your name: ")
let client: TClientClient = (socket, await socket.recvLine())
 
clients.add client
Line 1,191:
proc serve() {.async.} =
var server = newAsyncSocket()
server.bindAddr(TPortPort(4004))
server.listen()
 
Anonymous user