a few unsorted things:

  • no need for c.getFd.getPeerAddr(Domain.AF_INET) use acceptAddr


  • waitFor starts its own poll loop (nothing else will run async), so if you want to asyncSleep in an async proc you have to await its result!
  • If i see correct BOTH your client and your server starts and both readLine forever. Cause noone is sending data. change your client to send a "hello" to the server on connection and you should see.
  • It might be still the case (it was a few month ago when i tried it) that reading from stdin is not working in an async manner! So you could try to read from stdin in a thread:


2018-03-12 13:53:08

Indeed, I was going to mention the ChatApp example from Nim in Action. Pretty sure it implements precisely what you're trying to implement.

See both server and client here: https://github.com/dom96/nim-in-action-code/blob/master/Chapter3/ChatApp

2018-03-12 15:48:53

In regards to some other things written here:

I'm "pretty sure" that I observed in Windows that asyncdispatch would use multiple different threads to run the code.

It doesn't, and it cannot do that unless you pass --threads:on. This is assuming that Windows doesn't do something weird internally, like create threads to handle IO (which wouldn't surprise me), but Nim's asyncdispatch loop is definitely single threaded.

@r3d9u11 The issue with your code is, as others mentioned, that you're calling stdin.readLine which is a blocking call. If you're performing IO and it doesn't return a Future then assume it is blocking.

The ChatApp we linked above shows how to handle this by creating a new thread to read from stdin without blocking your program.

2018-03-12 15:57:03
I thought that all code into async function will be async too my bad. A lot of thanks for all for your clarifications and hints!
2018-03-12 19:10:17