Thx a lot Luis ;-) The Java server now send me a signal for "end of transmission" so I do not have the check the weight of the transfer... "Why are you using a while to read return code, filename and size? Three socket.readline should be enough." yeah sure, but its just cheesy test code lol Thx again for your rapid reply and have a nice day ! Luis Parravicini wrote: > On Wed, Oct 1, 2008 at 10:53 AM, Serge Savoie <seurdge.sawa / gmail.com> > 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 -- Posted via http://www.ruby-forum.com/.