Hello again :)
I think there must be some kind of strange threading voodoo going on - I
have this working, in a way. What happens with this is that after multiple
people connect, eventually the threads of all but the last one seem to stop
running after typing a few lines, seemingly stalling on the
user.socket.gets. The last user to connect can continue to type, and
everything is still echoed out to all the other users, but nothing they type
ever echoes to anyone. Checking netstat, the buffers on the other
connections continue to grow as other users type, but gets never seems to
happen. Is this a problem with gets or threading?
Thanks,
David
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