From: Robert Klemme Date: 2009-01-24T01:10:20+09:00 Subject: Re: Can't read more than one message from a socket 2009/1/21 Chris Birkinshaw : > I am connecting to a server and then waiting to receive messages over > the socket. For each message received I wish to then execute some code. > > I have tried recv, gets, and readpartial all with no luck. > > I tried something like this: > > loop { > data = socket.recv( 100 ) > puts "Line received" > puts data > } > > What I see when sending messages from the server is that the first > message is received and printed, then the program hangs for 15 secs, > then the loop starts but each time the data is empty. > > I am obviously doing something really stupid but I've spend hours now on > this so if someone could hint at how to do this I would be most > grateful. Are both processes Ruby processes? In that case it's certainly a lot more hassle free to use DRb. If not, you should define a protocol yourself. Either use messages with a fixed length or transmit the length as first item or use a special EOM marker (you could use a line delimiter for this, which has the advantage that you can use gets or each without arguments). Kind regards robert -- remember.guy do |as, often| as.you_can - without end