TCPClient
Use your TCP connections with working timeout.
Description
This gem implements a customizable TCP client class that gives you control over time limits. You can set time limits for individual read or write calls or set a deadline for entire call sequences.
It has a very small footprint, no dependencies and is easily useable.
Sample
require 'tcp-client'
cfg =
TCPClient::Configuration.create(
buffered: false,
ssl_params: {
min_version: :TLS1_2
}
)
response =
TCPClient.with_deadline(1.5, 'www.google.com:443', cfg) do |client|
client.write("GET / HTTP/1.1\r\nHost: www.google.com\r\n\r\n")
client.readline("\r\n\r\n")
end
puts(response)
For more samples see the examples dir
Installation
You can install the gem in your system with
gem install tcp-client
You can use Bundler to add TCPClient to your own project:
bundle add tcp-client
After that you only need one line of code to have everything together
require 'tcp-client'