From: Brian Candler Date: 2003-05-16T20:45:17+09:00 Subject: Re: TCP Sockets On Fri, May 16, 2003 at 07:53:39PM +0900, Dominik Werder wrote: > But what should I gonna do if I have to read binary data from one or more > connections and want to line them up in packets to send them over a single > connection to another host. In this case I can't wait for a newline or EOF > cause the binary data may not contain CR/LF. That would mean mixing the binary streams in a non-deterministic way, which doesn't sound very useful to me. Half a message from stream A followed by a quarter message from stream B, followed by... I think you need to understand the message boundaries within a stream for this sort of multiplexing to be useful. > Or if the sending server hangs > the connection is established but theres no data flowing.. and so my > connection hangs too (forever?) That's fine, your thread can hang as long as you like, and you can protect it with a timeout: try require 'timeout' timeout(5) do sleep 10 end > How do for example P2P clients do that? One thread per connection? I don't know what you mean by 'P2P', but a server talking to multiple clients would indeed normally have a separate thread per client. There's an example of a fake pop3 server at http://www.rubygarden.org/ruby?SingletonTutorial (at the end of section 2) Regards, Brian.