From: Nathan Clark Date: 2010-12-08T06:12:29+09:00 Subject: Re: HTTP POST request --> Ruby server On Tue, Dec 7, 2010 at 3: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 } Put a print statement after this line, to make sure it isn't actually blocking on that last character (since it's printing a character at a time). If the socket is still open but has no more data to read, readchar may be waiting for more data. Usually clients will include a "Content-Length" header field, specifying the length of the content body (in bytes). Since clients will often leave the connection open rather than closing/reopening whenever more communication is needed, you will probably need to check the amount of data read against the value in this header to see if you've reached the end of the request. > 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 > > Can't figure why :o >