Sinatra 随机启动演示服务器
Sinatra randomly starts demo server
我正在编写一个小的代理检查实用程序,这是我目前的代码:
require "thread"
require "socket"
require "http"
require "sinatra"
host = "0.0.0.0"
port = 6660
Thread.new do
class App < Sinatra::Base
set :server, :thin
get '/' do
env.select {|k,v| k.start_with? 'HTTP_'}.collect {|pair| "#{pair[0].sub(/^HTTP_/, '')}: #{pair[1]}"}.join "\n"
end
end
App.run! host: host, port: port
end
sleep 2
queue = Queue.new
ext_ip = Socket.ip_address_list.detect{|intf| intf.ipv4?}.ip_address # and !intf.ipv4_loopback? and !intf.ipv4_multicast? and !intf.ipv4_private?}
url = "http://#{url}:#{port}/"
Thread.new do
queue << proxy.split(":") while proxy = gets.chomp
end
servers = [1, 2, 3, 4, 5].map {
Thread.new do
until queue.empty?
p "shit", queue.pop
headers = HTTP.via(*queue.pop).get(url).split("\n").map {|l| l.split(" ", 2)}.to_h
p headers
end
end
}.each do |t|
t.join
end
出于某种原因,这不仅会在 localhost:6660 上启动一个 sinatra 服务器,还会在 localhost:4567
上启动一个 sinatra 服务器,我完全不明白为什么。
这是我得到的输出:
== Sinatra (v1.4.6) has taken the stage on 6660 for development with backup from Thin
Thin web server (v1.6.3 codename Protein Powder)
Maximum connections set to 1024
Listening on localhost:6660, CTRL+C to stop
Stopping ...
== Sinatra has ended his set (crowd applauds)
== Sinatra (v1.4.6) has taken the stage on 4567 for development with backup from Thin
Thin web server (v1.6.3 codename Protein Powder)
Maximum connections set to 1024
Listening on localhost:4567, CTRL+C to stop
第二台服务器来自哪里??当我在浏览器中打开它时,它是默认的 Sinatra 启动画面。
而不是 require "sinatra"
,使用 require "sinatra/base"
. Requiring just sinatra
enables the built in server, which will start serving the (empty) Sinatra::Application
app in an at_exit
handler。
我正在编写一个小的代理检查实用程序,这是我目前的代码:
require "thread"
require "socket"
require "http"
require "sinatra"
host = "0.0.0.0"
port = 6660
Thread.new do
class App < Sinatra::Base
set :server, :thin
get '/' do
env.select {|k,v| k.start_with? 'HTTP_'}.collect {|pair| "#{pair[0].sub(/^HTTP_/, '')}: #{pair[1]}"}.join "\n"
end
end
App.run! host: host, port: port
end
sleep 2
queue = Queue.new
ext_ip = Socket.ip_address_list.detect{|intf| intf.ipv4?}.ip_address # and !intf.ipv4_loopback? and !intf.ipv4_multicast? and !intf.ipv4_private?}
url = "http://#{url}:#{port}/"
Thread.new do
queue << proxy.split(":") while proxy = gets.chomp
end
servers = [1, 2, 3, 4, 5].map {
Thread.new do
until queue.empty?
p "shit", queue.pop
headers = HTTP.via(*queue.pop).get(url).split("\n").map {|l| l.split(" ", 2)}.to_h
p headers
end
end
}.each do |t|
t.join
end
出于某种原因,这不仅会在 localhost:6660 上启动一个 sinatra 服务器,还会在 localhost:4567
上启动一个 sinatra 服务器,我完全不明白为什么。
这是我得到的输出:
== Sinatra (v1.4.6) has taken the stage on 6660 for development with backup from Thin
Thin web server (v1.6.3 codename Protein Powder)
Maximum connections set to 1024
Listening on localhost:6660, CTRL+C to stop
Stopping ...
== Sinatra has ended his set (crowd applauds)
== Sinatra (v1.4.6) has taken the stage on 4567 for development with backup from Thin
Thin web server (v1.6.3 codename Protein Powder)
Maximum connections set to 1024
Listening on localhost:4567, CTRL+C to stop
第二台服务器来自哪里??当我在浏览器中打开它时,它是默认的 Sinatra 启动画面。
而不是 require "sinatra"
,使用 require "sinatra/base"
. Requiring just sinatra
enables the built in server, which will start serving the (empty) Sinatra::Application
app in an at_exit
handler。