> I am able to download a file via sockets
Fine that you had some success. Without studying your actual code, I would suggest that you use an outer loop to archive your desire. In Nim, as in many other programming languages, loops like "while" and "for" can be nested. And note, that in Nim we generally try to avoid global code at all, at least as long as the programs are not tiny. We often use an arbitrary called main function like in C, and only call the main entry point like main() from global code. Having all the code in procs, makes it cleaner, and it may even improve performance, as the C backend can better optimize and don't have to access many global variables.