From: David Thiel Date: 2001-05-24T08:07:47+09:00 Subject: [ruby-talk:15632] Re: more fun with TCPServer I put a couple puts statements in the loop, at the beginning and after the write, to debug, and it does appear to actually be stalling on the gets - here's the user class form user.rb if you want to try and run it. I'm sure there's lots of other flaws in the scheme, though, this is my first time playing with threads. :) -David class User @@input = 0 def initialize(socket) @socket = socket end def write(line) socket.print "#{line}" end attr_accessor :linenum, :socket, :name, :idle, :thread, :address def to_s "#{@linenum}, #{@name}, #{@address}" end end ----- Original Message ----- From: "Dave Thomas" To: "ruby-talk ML" ; Sent: Wednesday, May 23, 2001 3:53 PM Subject: [ruby-talk:15631] Re: more fun with TCPServer > "David Thiel" writes: > > > require 'socket' > > require 'thread' > > require 'user.rb' > > users = [] > > port = 4242 > > server = TCPServer.new('localhost', port) > > > > while (session = server.accept) > > users << User.new(session) > > users.last.thread = Thread.new(users.last) { |user| > > user.linenum = users.length > > user.address = user.socket.addr > > puts "connected: #{user.to_s}" > > until user.socket.eof > > input = user.socket.gets > > puts input > > users.each {|user| user.write(input) } > > end > > users.delete_at(user.linenum - 1) > > user.socket.close > > } > > end > > In this scheme, what happens if one use stops receiving the stuff you > write? Eventually, all the user threads will block on the user.write > in the loop, and hence won't get around to reading. > > Could this be what you're seeing? > > > Dabe > >