A TCP client implementation with working timeout support.


This Gem implements a TCP client with (optional) SSL support. It is an easy to use, versatile configurable client that can correctly handle time limits. Unlike other implementations, this client respects predefined/configurable time limits for each method (connect, read, write). Deadlines for a sequence of read/write actions can also be monitored.


require 'tcp-client'

# create a configuration:
# - don't use internal buffering
# - use TLS 1.2 or TLS 1.3
cfg = TCPClient::Configuration.create(
  buffered: false,
  ssl_params: {min_version: :TLS1_2, max_version: :TLS1_3}

# request to
# - limit all network interactions to 1.5 seconds
# - use the Configuration cfg
# - send a simple HTTP get request
# - read the returned message and headers
response =
  TCPClient.with_deadline(1.5, '', cfg) do |client|
    client.write("GET / HTTP/1.1\r\nHost:\r\n\r\n") #=> 40
    client.readline("\r\n\r\n") #=> see response


For more samples see the samples dir


Use Bundler to use TCPClient in your own project:

Add to your Gemfile:

gem 'tcp-client'

and install it by running Bundler:


To install the gem globally use:

gem install tcp-client

After that you need only a single line of code in your project to have all tools on board:

require 'tcp-client'