Working With TCP Sockets

You Don't Have to be a C Programmer to Understand Socket Programming

A short, concise guide that teaches Rubyists the basics of socket programming, and then some!

Do you know how your web server opens a socket, binds to an address, and accepts a connection?

I did a lot of web programming before I had enough knowledge to dig in and figure this stuff out.

I knew that other developers had a better grasp on the full stack than I did, but diving deep under the hood is one of the things that really made me a better developer all around.

I recently read a great thread that asked "What did the really successful programmers do differently?". This response really caught my eye:

Be ready, willing, & able to deep dive multiple levels at any time. You must know what's going on under the hood. There is a strong correlation between "number of levels of deepness understood" and "programming prowess".

In this book I'll teach you these fundamentals using Ruby. I'll start with the fundamentals that are portable to any environment. Then I'll show you the beautiful abstractions that Ruby has layered on top of them.

Learning this stuff doesn't just apply to Ruby, or any other language. Every modern programming language has support for networking. Every language has their own way of doing things. But all modern languages support the Berkeley Sockets API. Ruby is no exception. There's certainly plenty of syntactic sugar, but below the sugar you can use the same Sockets API that you would in C, Java, Python, whatever. This is portable knowledge that will serve you for many years to come.

What other readers said

What you'll learn:

  • The steps in the lifecycle of servers and clients.
  • The various ways that we can read and write data in Ruby, and when they're appropriate.
  • All the things you were never quite sure about: EOF, listen queues, TCPNODELAY, and tons more.
  • The low level methods required for constructing sockets, as well as the syntactic sugar that Ruby provides.
  • Known methods that will help you improve socket performance.
  • Basics of SSL sockets.
  • Should you write a lot of data at once or chunk it into smaller writes?
  • Get comfortable with the socket programming API that's available in any modern programming language.
  • More example code than you shake a stick at!
  • A look at 6 different architecture patterns for building concurrency into your network programs.
  • A closer look at a few different protocols: FTP and Redis.
  • Multiplexing connections, non-blocking IO, socket timeouts, socket options, and more...
  • The same practical, straightforward approach as my previous book.

The Details

The Book

The first section of the book is all about learning the fundamentals of programming with sockets. This includes creating sockets, the client and server lifecycle, and reading/writing data.

The second section of the book covers the harder stuff. This includes various methods for optimizing socket operations, the proper way to do socket timeouts in Ruby, SSL sockets, multiplexing connections, and more.

The last section applies this knowledge to a real world problem by writing an FTP server. In this section of the book I take a simple, sequential FTP server and rewrite it 6 times using different architecture patterns to demonstrate networking concurrency in Ruby and ways to organize your socket code. You'll see these same patterns in libraries like Puma, Unicorn, Thin, and EventMachine.

Details:
  • 185 page PDF with lots of code samples
  • e-reader formats for ePub, MOBI, and TXT
  • directory of sample code from the book for further tweaking
  • DRM free
  • Read a sample chapter

The Video

Follow along with me as I write a pure-Ruby evented IO system, similar to EventMachine. We literally start with nothing and end up with something that we use to build echo servers, a redis client, and an HTTP server. In the course of the video you'll see lots of examples of stuff that's covered in the book: connection multiplexing, nonblocking IO, message framing, and more.

Details:
  • 55 minute screencast
  • All live coding with me
  • high resolution .mov files
  • DRM free

Cheat Sheet

Keep what you learn close at hand with the cheat sheet. It's a great recap of what's covered in the book. It comes as a single-page PDF and is print-friendly.

Team License

Get it for the whole team! The team license is good for 50 licenses so your whole team can take advantage.


  • Ebook

  • +
  • Cheat Sheet

  • +
  • Video

  • +
  • Team License

  • Ebook

  • +
  • Cheat Sheet

  • +
  • Video

  • Ebook

Money-back Guarantee

If it's not working for you then it's not working for me.

If, for any reason, you're not happy with what you get just send me an email: I'll give you your money back and you keep everything. I want you to be happy.

I'm Jesse Storimer.

For the past 4 years I've been solving hard problems at Shopify, one of the largest, busiest Ruby on Rails sites on the web.

My journey into the world of Unix programming started while working on Shopify's infrastructure and continues today. I live near Kemptville, Canada with my wife and daughter.

And, yes, I'm working on my Unix beard.

Questions? Email me at jesse@jstorimer.com.