From: Chananya Freiman Date: 2010-12-08T07:36:19+09:00 Subject: Re: HTTP POST request --> Ruby server Jeremy Bopp wrote in post #967039: > On 12/7/2010 2:48 PM, Chananya Freiman wrote: >> >> str = "" >> (1..560).each { |a| str += peer.readchar } >> print str > > peer.readchar is blocking because there is no further data available but > the stream is still open. > > Are you certain that your two examples both accurately reflect the code > you're actually using? In both cases you are creating an inclusive > range over which to iterate, and both ranges go from 1 to 560. As a > result, your loops will run 560 times, so if your data is only 559 bytes > long, you will run peer.readchar one more time than you have bytes > available. In that case, both loops should block at the peer.readchar > call in the 560th iteration. > > -Jeremy Yes that's what should happen, but the first one didn't block for some reason. Anyway, the problem is solved now. I did try using readbytes(length) where length is the Content-Length value, but it blocks wheres (length.to_i).times do data += peer.readchar end doesn't. But, as long as I get the POST data, I am happy. -- Posted via http://www.ruby-forum.com/.