Module: PoolParty::Pinger::ClassMethods

Defined in:
lib/poolparty/modules/pinger.rb

Instance Method Summary collapse

Instance Method Details

#ping_port(host, port = 22, retry_times = 400) ⇒ Object

Test to see if the host has the available port open for response.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/poolparty/modules/pinger.rb', line 7

def ping_port(host, port=22, retry_times=400)
  connected = false
  dputs "pinging #{host}:#{port} for #{retry_times}"
  retry_times.times do |i|
    begin
      timeout 5 do
        break if connected = TCPSocket.new(host, port).is_a?(TCPSocket)
      end            
    rescue Exception => e
      sleep(2)
    end
  end
  connected
end