From: Jeremy Bopp Date: 2010-12-08T06:13:29+09:00 Subject: Re: HTTP POST request --> Ruby server On 12/7/2010 2:48 PM, Chananya Freiman wrote: > After more debugging it looks like Ruby gets stuck when it tries to add > the very last character, AFTER the POST data (why is there a character > there anyway?) to a string. > So, in this example the whole packet is 559 characters long. > This code prints it just fine: > > (1..560).each { |a| print peer.readchar } > > Yet this one gets stuck (inside the loop, it doesn't even get to the > print): > > 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