From: Francis Cianfrocca Date: 2007-03-07T10:49:20+09:00 Subject: Re: How to do INTERESTING things with Ruby sockets??? ------=_Part_205357_6118624.1173232155433 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline On 3/6/07, theosib@gmail.com wrote: > > I've done quite a bit of reading about socket programming in Ruby, but > most of the examples show simple cases of accepting a socket > connection, spitting out some fixed bit of data, and then closing. > What about socket connections where you can't predict the length or > timing of data that you'll receive? None of the available web pages > give any hint of how to work interactively with sockets. > > Here are a few things that I was hoping maybe some knowledgable people > could help me figure out how to do with sockets in Ruby: > > - Block until 1 or more bytes have been received, and then return as > many as have arrived (even if fewer than some buffer size) > > - Block until a fixed number of bytes have been received, or a time- > out has elapsed > > - Check how many bytes have been received without blocking > > - Detect when the other end has closed the socket > > - Distinguish between a timeout and a closed socket You don't say if this is a learning exercise in low-level socket programming or if you actually have to develop an app. If it's the latter, you may want to look at the Ruby/EventMachine library. It wraps up the low-level socket issues so you can concentrate on the app-level code. ------=_Part_205357_6118624.1173232155433--