https://github.com/mblumtritt/tcp-client
Use your TCP connections with working timeout.
https://github.com/mblumtritt/tcp-client
ruby ruby-gem socket tcp tcp-client tcp-socket timeout
Last synced: 7 months ago
JSON representation
Use your TCP connections with working timeout.
- Host: GitHub
- URL: https://github.com/mblumtritt/tcp-client
- Owner: mblumtritt
- License: bsd-3-clause
- Created: 2018-02-17T22:00:20.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2024-05-12T19:06:50.000Z (about 1 year ago)
- Last Synced: 2024-10-31T13:25:15.489Z (8 months ago)
- Topics: ruby, ruby-gem, socket, tcp, tcp-client, tcp-socket, timeout
- Language: Ruby
- Homepage:
- Size: 194 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# TCPClient 
Use your TCP connections with working timeout.
- Gem: [rubygems.org](https://rubygems.org/gems/tcp-client)
- Source: [github.com](https://github.com/mblumtritt/tcp-client)
- Help: [rubydoc.info](https://rubydoc.info/gems/tcp-client/TCPClient)## 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
```ruby
require 'tcp-client'# create a configuration:
# - don't use internal buffering
# - use at least TLS 1.2
cfg =
TCPClient::Configuration.create(
buffered: false,
ssl_params: {
min_version: :TLS1_2
}
)# request to Google.com:
# - 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, 'www.google.com:443', cfg) do |client|
client.write("GET / HTTP/1.1\r\nHost: www.google.com\r\n\r\n") #=> 40
client.readline("\r\n\r\n") #=> see response
endputs(response)
```For more samples see [the examples dir](./examples)
## Installation
You can install the gem in your system with
```shell
gem install tcp-client
```You can use [Bundler](http://gembundler.com/) to add TCPClient to your own project:
```shell
bundle add tcp-client
```After that you only need one line of code to have everything together
```ruby
require 'tcp-client'
```