tasyncsend4757.nim 516 B

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