1. 11

How does a beginner go about learn networking basics as well as being able to apply some network programming concepts using Golang? I do know the basics of Golang but I have no idea where to start with the networking bit, I have heard of the OSI model but I am not sure if it is a proper way to understand networking.

  1.  

  2. 6

    Hey there – I had the same question a while back and compiled a list of resources/curriculum to learn networking, using Go. You can find everything here. I think once you get the networking concepts down (using for example Beej’s guide). You can translate the C code into Go code (Go in fact just makes the same system calls, with some layers of abstraction on top) and will be well on your way!

    1. 1

      Thank you! I think this is exactly what I am looking for.

    2. 2

      It depends how you learn best. Go is already fairly high-level.

      Here are a few things I would play with:

      • Install Wireshark. This is a tool that allows you to record and analyze your network traffic. There are a TON of options and acronyms so don’t be afraid. Just keep it around and play with it while doing the other stuff. Try the “Follow TCP stream” option. This is more to get a sense of what is happening and learn by osmosis.
      • Find some references on Berkley sockets. This is the API that is used for networking on Linux, macOS and all the other UNIX operating systems. It’s important to understand what bind(), listen(), connect() and accept() operations do.
      • Implement a small server and client in Go with the higher-level version: https://golang.org/pkg/net/ .
      • Then read their implementation. Maybe try to use the underlying syscalls directly: https://golang.org/pkg/syscall/

      That should be enough for day-to-day programming. I also encourage you to read up on how DHCP, ICMP, TCP/IP, DNS resolution works. And higher-level protocols such as HTTP.

      1. 1

        Thank you, do you have any ideas for little projects I could do after I am done learning the basics and have played around with the implementations?

        1. 2

          You could write a little file-sending tool.

          You need a client mode that opens the file and tries to forward it to a server. For example the usage could be filecli send <filename> <targethost[:port]> Eg: filecli send /etc/password myserver:8848.

          You need a server that accepts new client connections and puts the file in a per-determined location. For example the usage could be filecli recv <bind-addr:[port]> <directory>. Eg: filecli recv 0.0.0.0:8848 ./Downloads.

          At first you just want to get the raw data for each connection and store them into incremental names. Eg: ~/Download/file-1 ~/Downloads/file2. Each connection can only send one file and the file is closed at the same time as the connection.

          Once you have that, think about what issues the implementation has and how you could augment it, maybe by creating some sort of exchange protocol yourself. What happens if the connection gets interrupted during the transfer.

      2. 2

        Implement a protocol, use the Go documation, avoid frameworks or anything like that, because then you will only learn that framework. It also helps to be able to read specifications, whether it’s an RFC or not. Good luck with that! :)