The following in the call to the interface of the currency, will often get stuck, set the connection timeout will not throw an exception, the code is as follows (the default connection timeout is nil, refer to: https://github.com/ruby/ruby/pull/269):
require ‘net/http‘require ‘json‘require ‘byebug‘uri = URI(‘https://www.binance.com/api/v1/ticker/24hr?symbol=EOSBTC‘)req = Net::HTTP::Get.new(uri)loop do res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => uri.scheme == ‘https‘) do |http| http.open_timeout = 1 http.request(req) end puts "#{JSON.parse res.body}" puts "http request complete." sleep 1end
Do not know why, with http.open_timeout = 1
This setting does not work, instead of the options in the start configuration can be timed out throws an exception, as follows:
res = Net::HTTP.start(uri.hostname, uri.port, :use_ssl => uri.scheme == ‘https‘, :open_timeout => 1) do |http| http.request(req) end
Connection timeout issues in Ruby http/net