puts and gets over IP 
Author Message
 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?

Frank



Tue, 20 Apr 2004 17:23:06 GMT  
 puts and gets over IP

Quote:
> -----Original Message-----

> 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).

_____________________________________________________________

bol?tov.ru creative group
http://www.bolotov.ru/



Wed, 21 Apr 2004 19:03:42 GMT  
 puts and gets over IP
Cool!
Thx a lot

Frank



Wed, 21 Apr 2004 20:36:03 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. How about putting IP address in the session?

2. Getting awk (or sed or anything else) to put single quotes into file

3. Putting or Getting multiple files with RxFtp

4. BUG?: HP-UX 10.20 and IO#gets followed by IO#puts

5. Communication puts/gets

6. gets/puts - encoded ?

7. question on puts, gets and eof?

8. puts/gets to sockets?

9. Getting a scale value put onto a label...

10. What IP socket gets?

11. Getting TCP/IP Information

 

 
Powered by phpBB® Forum Software