From: Joel VanderWerf Date: 2009-01-09T06:48:17+09:00 Subject: Re: How to realize that a TCPSocket doesn't give any more lines as answer? kazaam@oleco.net wrote: > Hi, > I'm writing a little tcp-client which connects to a tcp-server, sends a command and recieves an answer. If I do something like that: > > #!/usr/bin/env ruby > > $VERBOSE=true > > require 'socket' > ... > begin > socket = TCPSocket.new($ip,$port) > rescue > puts "error: #{$!}" > exit 1 > end > > socket.print command > > answer=socket.gets > > socket.close > > > It works if the server sends just one line. But I don't know how many lines the server answers. So I tried something like that: > > answers=[] > while answer=socket.gets > answers< end > > But this results in the while-loop never ending. Even if just one line is the answer the while loop does simply never end :( Any idea how to do this? Try socket.gets(nil) -- that waits for EOF instead of newline. -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407