Do you know how your web server opens a socket, binds to an address, and accepts a connection? I did a lot of Rails development before I understood the mechanics of the network stack I was working on top of. Forget those 1,000+ page networking manuals; Working With TCP Sockets zeroes in on exactly what you need to know as a Ruby developer working on the web today. After reading the book, you’ll have a good understanding of socket programming basics—enough to write servers, client libraries, or concurrent network programs.
This book was written and produced entirely by the author. We are proud to be distributing it.
Buy Now
About this Book
- 185 pages
- Published:
- Release: P1.0 (2013-01-18)
- ISBN: pending
The book is organized to start with the lowest-level concepts, then work up to the high-level Ruby wrappers, and finally up to more complex stuff. In the beginning you’ll find out how to create sockets using the lowest-level calls that Ruby offers. Following that, you’ll see the bind/listen/accept or bind/connect lifecycle methods for servers and clients, respectively. You’ll then learn about the various high-level wrapper classes that Ruby provides so you don’t have to worry about the boilerplate details.
The middle section of the book is all about more advanced topics such as properly implementing socket timeouts, SSL sockets, buffering, and more. The last section puts all the abstract stuff into practice by building an FTP server several times over using different concurrency patterns.
All the code in the book is written in Ruby, but this stuff doesn’t just apply to Ruby. The Berkeley Sockets API has been in use for more than 25 years and has bindings in any modern programming language. You can learn the fundamentals in Ruby, then take them with you when you’re programming in Python, Go, C, or whatever. This is portable knowledge that will serve you for many years to come.
This book was written and produced entirely by the author. We are proud to be distributing it.
What You Need
The code samples in the book are written against Ruby 1.9.3 and assume a working knowledge of Ruby.
Contents and Extracts
Your First Socket
Establishing Connections
Client Lifecycle
Exchanging Data
Sockets Can Read
Sockets Can Write
Buffering
Our First Client/Server
Socket Options
Non-blocking IO
Multiplexing Connections
Nagle’s algorithm
Framing Messages
Timeouts
DNS Lookups
SSL Sockets
Urgent Data
Network Architecture Patterns
Serial
Thread per connection
Preforking
Thread Pool
Evented (Reactor)
Hybrids
Closing Thoughts


