0
我似乎無法得到這個工作; Thread.start
爲什麼不啓動?爲什麼不能啓動Thread.start?
# encoding: utf-8
require 'socket'
print "choose host: "
host = gets.chomp
print "choose starting port: "
sport = gets.to_i
print "choose ending port: "
eport = gets.to_i
def scanner (sport, eport, host)
while sport <= eport
begin
s = TCPSocket.new(host, sport)
if s
puts "Port #{sport} is open!"
end
rescue
puts "Port #{sport} is closed!"
end
sport += 1
end
end
Thread.start([scanner]sport, eport, host)
不知道,但也許你需要Thread.join。 ?也許主線程正在退出導致整個進程在工作線程完成之前終止。 –
@ AndrewTomazos-Fathomling:這正是這裏發生的事情。你應該把它作爲答案。 –
好吧,它的工作原理:) – Ba7a7chy