From: Michal Suchanek Date: 2006-06-07T01:36:17+09:00 Subject: Re: Multiple threads on single port On 6/6/06, Stuart Brand wrote: > Hi all > > Can I use Ruby threads to have more then 1 server process running on the > same port > > something like > > require 'socket' > port = (ARGV[0] || 80).to_i > server = TCPServer.new('localhost', port) > threads = [] > > > 10.times do |i| > threads[i] = Thread.new { > while (session = server.accept) > puts "Request: #{session.gets}" > session.print "HTTP/1.1 200/OK\r\nContent-type: text/html\r\n\r\n" > session.print "

#{Time.now}

\r\n" > session.close > end > } > end > > Would this produce 10 processes that could take independent connection? This will probably create multiple threads that accept connections. I only did while(session = server.accept) Thread.new{...} end and it was in C. But you should be aware of the fact that depending on the request processing you do in your thread you may not get any thread switch until the request is handled. But at least print should probably trigger the ruby thread scheduler. HTH Michal