From: Manuel Zabelt Date: 2001-08-14T03:06:49+09:00 Subject: [ruby-talk:19646] Threading a TCPServer Hello! I wrote the following little script: require 'socket' class NetJobsSession def initialize(connection) @connection=connection end def write(text) @connection.write text end def send_http_header @connection.write "HTTP/1.1 200 OK\r\n" @connection.write "Content-Type: text/plain\r\n\r\n" end def close @connection.close end end class NetJobsServer def initialize(port) @listen=TCPServer.new('0.0.0.0', port) end def run loop{ Thread.start(@listen.accept){ |aConnection| session=NetJobsSession.new(aConnection) session.send_http_header session.write "#{Time.now} #{Thread.current}" puts "#{Time.now} #{Thread.current}" sleep 5 session.close } } end end server=NetJobsServer.new(4200) server.run If I let two browsers connect to this TCPServer I thought there would be two threads started. But what happens is, that when the first http-browsers connects to my server a new thread is created, but if (within the 5 seconds sleep time) a seccond browser connects to the server two, there is no new Thread started, but the second browser gets the same answer from the server as the first one. Is this a problem of my browsers? Is there something wrong with my script? What can I do? thanks and greetings manu