Sha256: f3a0c8286b55cc41f17164f95e5a34ac6946a19661a3a7eef4c59ca78a9b4f20

Contents?: true

Size: 743 Bytes

Versions: 22

Compression:

Stored size: 743 Bytes

Contents

module RSence
module ArgvUtil

  # Tests, if the port on addr responds or refuses the connection.
  # Automatically replaces '0.0.0.0' with '127.0.0.1'
  def test_port( port, addr='127.0.0.1' )
    require 'socket'
    begin
      addr = '127.0.0.1' if addr == '0.0.0.0'
      if RUBY_VERSION.to_f >= 1.9
        sock = TCPSocket.open( addr, port )
      else
        begin
          sock = TCPsocket.open( addr, port )
        rescue NameError => e
          warn "TCPsocket not available, trying TCPSocket.."
          sock = TCPSocket.open( addr, port )
        end
      end
      sock.close
      return true
    rescue Errno::ECONNREFUSED
      return false
    rescue => e
      warn e.inspect
      return false
    end
  end

end
end

Version data entries

22 entries across 22 versions & 2 rubygems

Version Path
rsence-pre-2.3.0.4 lib/rsence/argv/test_port.rb
rsence-pre-2.3.0.3 lib/rsence/argv/test_port.rb
rsence-pre-2.3.0.2 lib/rsence/argv/test_port.rb
rsence-pre-2.3.0.1 lib/rsence/argv/test_port.rb
rsence-pre-2.3.0.0 lib/rsence/argv/test_port.rb
rsence-2.2.5 lib/rsence/argv/test_port.rb
rsence-2.2.4 lib/rsence/argv/test_port.rb
rsence-2.2.3 lib/rsence/argv/test_port.rb
rsence-2.2.2 lib/rsence/argv/test_port.rb
rsence-pre-2.2.2.1 lib/rsence/argv/test_port.rb
rsence-pre-2.2.2.0 lib/rsence/argv/test_port.rb
rsence-2.2.1 lib/rsence/argv/test_port.rb
rsence-2.2.0 lib/rsence/argv/test_port.rb
rsence-pre-2.2.0.38 lib/rsence/argv/test_port.rb
rsence-pre-2.2.0.37 lib/rsence/argv/test_port.rb
rsence-pre-2.2.0.36 lib/rsence/argv/test_port.rb
rsence-pre-2.2.0.35 lib/rsence/argv/test_port.rb
rsence-pre-2.2.0.34 lib/rsence/argv/test_port.rb
rsence-pre-2.2.0.33 lib/rsence/argv/test_port.rb
rsence-pre-2.2.0.31 lib/rsence/argv/test_port.rb