From: Robert Klemme Date: 2004-08-01T01:21:40+09:00 Subject: Re: Thread Questions "Max Kuffs" schrieb im Newsbeitrag news:410bc141$0$10406$91cee783@newsreader01.highway.telekom.at... > Hello, > > I would like to write a little TCPServer which communicates with > another ruby program on another computer. > > So i tried all with TCPServer. I could connect and it worked, but i > want to execute it in a thread and now the program halts when i open > the server. You got the logic wrong: typically you want to serve each client in a separate thread. Try this: require 'socket' SERVER_PORT = 4772 LISTEN_ON = '0.0.0.0' server = TCPServer.new LISTEN_ON, SERVER_PORT clients = 0 while true Thread.new( server.accept, clients += 1 ) do |con, clnt| puts "Connect with client #{clnt}" while ( line = ( con.gets ) ) puts "From client #{clnt}: #{line}" end puts "EOF #{clnt}" end end Note: I introduced "clients" and "clnt" just for the purpose of distinguishing output from different clients. Kind regards robert