Chat server: Difference between revisions
Content added Content deleted
m (→{{header|Go}}) |
|||
Line 1,162: | Line 1,162: | ||
<lang nimrod>import asyncnet, asyncdispatch |
<lang nimrod>import asyncnet, asyncdispatch |
||
type TClient = tuple[socket: |
type TClient = tuple[socket: AsyncSocket, name: string] |
||
var clients: seq[ |
var clients: seq[Client] = @[] |
||
proc sendOthers(client: |
proc sendOthers(client: Client, line: string) {.async.} = |
||
for c in clients: |
for c in clients: |
||
if c != client: |
if c != client: |
||
await c.socket.send(line & "\c\L") |
await c.socket.send(line & "\c\L") |
||
proc processClient(socket: |
proc processClient(socket: AsyncSocket) {.async.} = |
||
await socket.send("Please enter your name: ") |
await socket.send("Please enter your name: ") |
||
let client: |
let client: Client = (socket, await socket.recvLine()) |
||
clients.add client |
clients.add client |
||
Line 1,191: | Line 1,191: | ||
proc serve() {.async.} = |
proc serve() {.async.} = |
||
var server = newAsyncSocket() |
var server = newAsyncSocket() |
||
server.bindAddr( |
server.bindAddr(Port(4004)) |
||
server.listen() |
server.listen() |
||