From: me@... (Rick) Date: 2002-11-01T13:41:13+09:00 Subject: Re: Is this the best start to ruby socket server for flash clients? Thank you much for these your thoughts and direction. I will get the book and rethink the approach. In the mean time here's the latest greatest threaded approach: It rejects users at 250 sockets on windows 2000 server and 500 sockets on Redhat linux. This is because "default is limited to 1024 file descriptors, this is done with proc settings" and each socket takes two. Looking into how and if this limit should be increased. require "socket" @@threadsOpen = ThreadGroup.new listenIp = "0.0.0.0" listenPort = 1234 socket = TCPServer.new(listenIp,listenPort) socket.setsockopt(Socket::SOL_SOCKET, Socket::TCP_NODELAY, true) #IPPROTO_TCP for windows while thisThread = Thread.new(session = socket.accept) {|thisSession| lastMessage = nil while thisSession if thisSession.eof? #test if socket is closed puts ("session closed") thisSession.close thisThread.kill else #socket is open fromClient = thisSession.gets("\0") if lastMessage != fromClient # avoid repeating previous line toClient = fromClient lastMessage = fromClient else toClient = "beat\0" end thisSession.write(toClient) puts (toClient) end sleep .75 end } @@threadsOpen.add(thisThread) end