tasyncsend4757.nim 526 B

12345678910111213141516171819202122232425
  1. import asyncdispatch, asyncnet
  2. var port: Port
  3. proc createServer() {.async.} =
  4. var server = newAsyncSocket()
  5. server.setSockOpt(OptReuseAddr, true)
  6. bindAddr(server)
  7. port = getLocalAddr(server)[1]
  8. server.listen()
  9. while true:
  10. let client = await server.accept()
  11. discard await client.recvLine()
  12. asyncCheck createServer()
  13. var done = false
  14. proc f(): Future[void] {.async.} =
  15. let s = createAsyncNativeSocket()
  16. await s.connect("localhost", port)
  17. await s.send("123")
  18. done = true
  19. waitFor f()
  20. doAssert done