> -----Original Message-----
> From: Frank Benoit [mailto:mail02 / frankbenoit.de]
> Sent: Saturday, November 03, 2001 12:29 PM
> To: ruby-talk ML; undisclosed-recipients:
> Subject: [ruby-talk:24255] puts and gets over IP
>
>
> Hi
>
> When I make a server and client in Ruby and let them comunicate with
> puts and gets over TCPSocket/Server, the program hangs each time there
> is no more data and I call gets. But the eof? gives false. How can I
> figure out if there is more data?
By using Kernel.select. See manual for select(2) and page 426 of the pickaxe
book.

TIMEOUT = 0.001
while true
	next unless select [socket], nil, nil, TIMEOUT
	string = socket.read
end

Note that TIMEOUT isn't necessarily needed (just plain 'select [socket]'
will do) but is a good thing to do if you need multithreading (ruby won't
switch threads if it's in a system call).

_____________________________________________________________
Zagorodnikov Aristarkh | Lead Programmer | xm / bolotov-team.ru
bol?tov.ru creative group
http://www.bolotov.ru/