Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
19
Task/Echo-server/Nim/echo-server.nim
Normal file
19
Task/Echo-server/Nim/echo-server.nim
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import asyncnet, asyncdispatch
|
||||
|
||||
proc processClient(client: AsyncSocket) {.async.} =
|
||||
while true:
|
||||
let line = await client.recvLine()
|
||||
await client.send(line & "\c\L")
|
||||
|
||||
proc serve() {.async.} =
|
||||
var server = newAsyncSocket()
|
||||
server.bindAddr(Port(12321))
|
||||
server.listen()
|
||||
|
||||
while true:
|
||||
let client = await server.accept()
|
||||
echo "Accepting connection from client", client.getLocalAddr[0]
|
||||
discard processClient(client)
|
||||
|
||||
discard serve()
|
||||
runForever()
|
||||
Loading…
Add table
Add a link
Reference in a new issue