1
1
# net_tcp_client
2
- [ ![ Gem Version] ( https://img.shields.io/gem/v/net_tcp_client.svg )] ( https://rubygems.org/gems/net_tcp_client ) [ ![ Build Status] ( https://travis-ci.org/rocketjob /net_tcp_client.svg?branch=master )] ( https://travis-ci.org/rocketjob /net_tcp_client ) [ ![ Downloads] ( https://img.shields.io/gem/dt/net_tcp_client.svg )] ( https://rubygems.org/gems/net_tcp_client ) [ ![ License] ( https://img.shields.io/badge/license-Apache%202.0-brightgreen.svg )] ( http://opensource.org/licenses/Apache-2.0 ) ![ ] ( https://img.shields.io/badge/status-Production%20Ready-blue.svg ) [ ![ Gitter chat ] ( https://img.shields.io/badge/IRC%20(gitter)-Support-brightgreen.svg )] ( https://gitter.im/rocketjob/support )
2
+ [ ![ Gem Version] ( https://img.shields.io/gem/v/net_tcp_client.svg )] ( https://rubygems.org/gems/net_tcp_client ) [ ![ Build Status] ( https://github.com/reidmorrison /net_tcp_client/workflows/build/badge .svg )] ( https://github.com/reidmorrison /net_tcp_client/actions?query=workflow%3Abuild ) [ ![ Downloads] ( https://img.shields.io/gem/dt/net_tcp_client.svg )] ( https://rubygems.org/gems/net_tcp_client ) [ ![ License] ( https://img.shields.io/badge/license-Apache%202.0-brightgreen.svg )] ( http://opensource.org/licenses/Apache-2.0 ) ![ ] ( https://img.shields.io/badge/status-Production%20Ready-blue.svg )
3
3
4
4
Net::TCPClient is a TCP Socket Client with automated failover, load balancing, retries and built-in timeouts.
5
5
6
- * http ://github.com/rocketjob /net_tcp_client
6
+ * https ://github.com/reidmorrison /net_tcp_client
7
7
8
8
## Introduction
9
9
@@ -36,7 +36,7 @@ prevent a network issue from "hanging" the client program.
36
36
require ' net/tcp_client'
37
37
38
38
Net ::TCPClient .connect(server: ' mydomain:3300' ) do |client |
39
- client.send (' Update the database' )
39
+ client.write (' Update the database' )
40
40
response = client.read(20 )
41
41
puts " Received: #{ response } "
42
42
end
@@ -48,7 +48,7 @@ Enable SSL encryption:
48
48
require ' net/tcp_client'
49
49
50
50
Net ::TCPClient .connect(server: ' mydomain:3300' , ssl: true ) do |client |
51
- client.send (' Update the database' )
51
+ client.write (' Update the database' )
52
52
response = client.read(20 )
53
53
puts " Received: #{ response } "
54
54
end
@@ -104,7 +104,7 @@ Servers are tried in a Random order.
104
104
~~~ ruby
105
105
tcp_client = Net ::TCPClient .new (
106
106
servers: [' server1:3300' , ' server2:3300' , ' server3:3600' ],
107
- policy: :ordered
107
+ policy: :random
108
108
)
109
109
~~~
110
110
@@ -145,15 +145,15 @@ Example run, the servers could be tried in the following order:
145
145
If a connection cannot be established to any servers in the list Net::TCPClient will retry from the
146
146
first server. This retry behavior can be controlled using the following options:
147
147
148
- * ` connect_retry_count ` [ Fixnum ]
148
+ * ` connect_retry_count ` [ Integer ]
149
149
* Number of times to retry connecting when a connection fails
150
150
* Default: 10
151
151
152
152
* ` connect_retry_interval ` [ Float]
153
153
* Number of seconds between connection retry attempts after the first failed attempt
154
154
* Default: 0.5
155
155
156
- * ` retry_count ` [ Fixnum ]
156
+ * ` retry_count ` [ Integer ]
157
157
* Number of times to retry when calling #retry_on_connection_failure
158
158
* This is independent of : connect_retry_count which still applies with
159
159
* connection failures. This retry controls upto how many times to retry the
@@ -184,16 +184,16 @@ Net::TCPClient.connect(
184
184
connect_retry_interval: 0.1 ,
185
185
connect_retry_count: 5
186
186
) do |client |
187
- # If the connection is lost, create a new one and retry the send
187
+ # If the connection is lost, create a new one and retry the write
188
188
client.retry_on_connection_failure do
189
- client.send (' How many users available?' )
189
+ client.write (' How many users available?' )
190
190
response = client.read(20 )
191
191
puts " Received: #{ response } "
192
192
end
193
193
end
194
194
~~~
195
195
196
- If the connection is lost during either the ` send ` or the ` read ` above the
196
+ If the connection is lost during either the ` write ` or the ` read ` above the
197
197
entire block will be re-tried once the connection has been re-stablished.
198
198
199
199
## Callbacks
@@ -210,7 +210,7 @@ Any time a connection has been established a callback can be called to handle ac
210
210
tcp_client = Net ::TCPClient .new (
211
211
servers: [' server1:3300' , ' server2:3300' , ' server3:3600' ],
212
212
on_connect: -> do |client |
213
- client.send (' My username and password' )
213
+ client.write (' My username and password' )
214
214
result = client.read(2 )
215
215
raise " Authentication failed" if result != ' OK'
216
216
end
@@ -224,13 +224,13 @@ tcp_client = Net::TCPClient.new(
224
224
servers: [' server1:3300' , ' server2:3300' , ' server3:3600' ],
225
225
on_connect: -> do |client |
226
226
# Set the sequence number to 0
227
- user_data = 0
227
+ client. user_data = 0
228
228
end
229
229
)
230
230
231
231
tcp_client.retry_on_connection_failure do
232
- # Send with the sequence number
233
- tcp_client.send (" #{ tcp_client.user_data } hello" )
232
+ # Write with the sequence number
233
+ tcp_client.write (" #{ tcp_client.user_data } hello" )
234
234
result = tcp_client.receive(30 )
235
235
236
236
# Increment sequence number after every call to the server
@@ -250,7 +250,7 @@ test on a daily basis, including connections over the internet between remote da
250
250
251
251
gem install net_tcp_client
252
252
253
- To enable logging add [ Semantic Logger] ( http ://rocketjob.github. io/semantic_logger ) :
253
+ To enable logging add [ Semantic Logger] ( https ://logger. rocketjob.io/) :
254
254
255
255
gem install semantic_logger
256
256
@@ -273,13 +273,13 @@ SemanticLogger.default_level = :trace
273
273
SemanticLogger .add_appender(file_name: ' development.log' , formatter: :color )
274
274
~~~
275
275
276
- If running Rails, see: [ Semantic Logger Rails] ( http ://rocketjob.github.io/semantic_logger /rails.html)
276
+ If running Rails, see: [ Semantic Logger Rails] ( https ://logger. rocketjob.io /rails.html)
277
277
278
278
### Support
279
279
280
280
Join the [ Gitter chat session] ( https://gitter.im/rocketjob/support ) if you have any questions.
281
281
282
- Issues / bugs can be reported via [ Github issues] ( https://github.com/rocketjob /net_tcp_client/issues ) .
282
+ Issues / bugs can be reported via [ Github issues] ( https://github.com/reidmorrison /net_tcp_client/issues ) .
283
283
284
284
### Upgrading to V2
285
285
@@ -303,7 +303,7 @@ Tested and supported on the following Ruby platforms:
303
303
- JRuby 1.7.23, 9.0 and above
304
304
- Rubinius 2.5 and above
305
305
306
- There is a soft dependency on [ Semantic Logger] ( http ://github.com/rocketjob /semantic_logger) . It will use SemanticLogger only if
306
+ There is a soft dependency on [ Semantic Logger] ( https ://github.com/reidmorrison /semantic_logger) . It will use SemanticLogger only if
307
307
it is already available, otherwise any other standard Ruby logger can be used.
308
308
309
309
### Note
@@ -314,8 +314,8 @@ Be sure to place the `semantic_logger` gem dependency before `net_tcp_client` in
314
314
315
315
[ Reid Morrison] ( https://github.com/reidmorrison )
316
316
317
- [ Contributors] ( https://github.com/rocketjob /net_tcp_client/graphs/contributors )
317
+ [ Contributors] ( https://github.com/reidmorrison /net_tcp_client/graphs/contributors )
318
318
319
319
## Versioning
320
320
321
- This project uses [ Semantic Versioning] ( http ://semver.org/) .
321
+ This project uses [ Semantic Versioning] ( https ://semver.org/) .
0 commit comments