From: Luis Parravicini Date: 2008-10-02T00:08:04+09:00 Subject: Re: Non blocking socket keep blocking on read ? On Wed, Oct 1, 2008 at 10:53 AM, Serge Savoie wrote: > But how do I know the weight of the received bytes ? I have think of > what you propose but can't find the way to "measure" the received stuff > !!! > > I have to use readline or gets to receive because the server (a java > server) only offer me buffered stream and recv and read dont work in > this case... It doesn't matter if the server is using a buffered stream, you'll get the bytes on the client anyway. Maybe something like this helps (haven't tried it): data = nil left = nombre_bytes while left > 0 # 8192 is an arbitrary buffer size buf = socket.read( left > 8192 ? 8192 : left ) # eof reached break unless buf left -= buf.size data += buf end @imageData = data Why are you using a while to read return code, filename and size? Three socket.readline should be enough. Bye -- Luis Parravicini http://ktulu.com.ar/blog/