Frank Preiswerk wrote:
> Now my problem is that "data = socket.recv(size)"
> seems to behave non-blocking for some reason. It does not wait...

I just wanted to add that as far as I know, you can't count on 
recv(1012) to read all the bytes sent when, say, only 500 bytes are 
sent.  recv() may only read 1 byte the first time it is called or it may 
read 200 bytes, or it may read all 500 bytes.  As a consequence, in 
order to get all the data you want out of the socket, you have to loop 
over recv() and either:

1) count the number of bytes that recv() read using String#length, and 
stop after a certain number of bytes, or

2) keep looping until recv encounters eof(i.e. a blank string is sent 
when the server closes the socket) and you have read all the data.

In your case, you say you want to block until all the data is read, so 
you could use read() and specify a large limit that is bigger than the 
length of the data that will be sent, and simply write:


all_data = read(8196)
#do something with all_data

My tests show read() will block and wait until it either reads all 8196 
bytes or the server closes the socket.



-- 
Posted via http://www.ruby-forum.com/.