Almost a year ago I discovered the Nim programing language.  It’s still in it’s early youth right now (hence that we’re not even at v1.0.0 yet), so it’s still a little bit of a pain to find any highly specific and in depth tutorials on certain subjects; one of them being networking.  Also a year ago I was working on what I called the C# Networking Tutorial Series.  To try to help out that "lack of tutorials," problem I’ve decided it would be good to port some of those applications over from C# to Nim.  Before we begin there are some things to note:

  1. In no way is this going to be (or can be) a one-to-one port.  'll try to keep the general flow of logic & structure the same.  Nim and C# are completely distinct languages.  What’s really obvious is their syntax.  Nim is very Python-like does have it’s own quirks. Whereas C# is the "original character, do not steal," of Java.
  2. Nim is still very much a young language.  It’s very likely that what you write now could be semi-broken two to three years from now.  Don’t stress about that though.  The Nim team is pretty good at telling you when something is deprecated and telling you how to update it.  At the time of writing this first section, Nim is at v0.17.x.  If any of the code here happens to be broken down the line, drop me an email.
  3. This is not a tutorial on networking (explicitly), but how to use Nim’s networking API.
  4. I work primarily on a Linux system, though Nim is cross platform.  So everything should work everywhere.
  5. I'll make sure the code provided can be run in just a command line interface, so we won't need to worry about GUI programming at all.  I'll try to keep the example simple and short, but I may include some larger and more complex applications (like a video game).  I will also include full source code for each example/tutorial.
  6. Make sure to have the nimble tool setup on your system.  If there is ever an extra dependency that is needed I’ll tell you where to grab it.  Setting it up on your OS though is your responsibility.


Source Code

Each of the tutorial sections have thier own full source examples.  If you want, you can download the entire collection (and project files) over here (GitHub mirror).  All of the code examples that I have included fall under the Unlicense (a.k.a. Public Domain), unless otherwise noted.  If you end up using my code somewhere, credit for authorship is appreciated.


How To Use This Guide

The main tutorial sequence is numbered off on the left.  You don't have to follow it in order, or read all of them, but it's recommended.  Everything else that isn't numbered are just one-off, "micro-tutorials."  I recommend reading all of the text.  Do not skimming anything.  When it comes to code, try not to just copy n' paste the example.  While it may take more time and effort, copying the code by writing it out in your editor is probably the best way to learn and memorize it.  It's what I do with most of the tutorials I read online.  Since we're also dealing with communications, I highly advise that you have a computer somewhere else in the world where you can run and test these programs.  While running a server & client on your local machine is fine for development, it's not realistic of what happens in the real world.  I'd recommend spinning up a VM on a service like Google Cloud PlatformDigital Ocean, or Amazon Web Services.

Contacting Me

If you have any questions, comments, or requests send me an email.  If you send me a message like "Can you look at my code?  I don't know what's wrong," or any other technical questions, I'm not likely to respond.  If you do copy n' paste code from here, and it turns out to be wrong, please do notify me so I can fix it.  All of the examples will be hosted on Github's Gist service.