In the interest of learning Go and more about Google’s Protocol Buffers, I followed this excellent tutorial to build a TCP client and server that would send and receive protobufs, all in Go.

I won’t rehash anything that was covered in the step by step guide. It goes over building a TCP client and server, writing a protocol buffer file and generating the code to work with it, as well as some Go features such as Goroutines. I will say that I had a bit of trouble with the install- I made a hash of it and ended up with the protocol buffer packages in one place, the Go libraries in another, and some very confused $PATH and $GOPATH variables. This stackoverflow answer was helpful, and I ended up just munging everything into my $GOPATH once I found where it had all been put. There was a lot of this:

sudo find / -type d -name "protobuf"

I would also suggest that you throw functions you want to reuse in a Constants.go file (with the appropriate packagename defined) so the server and client can share them. I also installed the Go Linter to run some checks against my formatting. There’s also a cool package for Sublime Text that provides an interface to Golint from that editor.

Working through the tutorial was an instructive experience. My finished client/server package is here, with loads of comments. Nice way to spend a few hours on a Saturday.