rubyのthreadとgserverで複数サーバを同時に立ち上げる
rubyのthreadとgserverで複数サーバを同時に立ち上げるには
gserver自身がthread実装みたいだけどまああえて動作空間を切りたいのよ。
require 'thread' require 'gserver' t=[] t.push Thread.new { class HttpServer1 < GServer def serve(io) puts "I'm gserver 1." io.gets io.puts <<EOF HTTP/1.0 200 OK Content-type: text/plain hello,world EOF end end server = HttpServer1.new(10001,"127.0.0.1") # server.audit = true # log server.start loop do sleep 1000 end } t.push Thread.new { class HttpServer2 < GServer def serve(io) puts "I'm gserver 2." io.gets io.puts <<EOF HTTP/1.0 200 OK Content-type: text/plain foo,bar,buzz EOF end end server = HttpServer2.new(10002,"127.0.0.1") # server.audit = true # log server.start loop do sleep 1000 end } t.each{|i| i.join}