2012-10-14 32 views
1

我有一個服務器,它經常斷開連接Ruby來從重置服務器讀取頻繁

$echo "GET hosts" | nc localhost 323 
a.host.com 
b.host.com 
c.host.com 

在閱讀紅寶石同樣的事情下面的代碼

s = TCPSocket.new(host,port) 
s.puts "GET hosts\n\n\r\r" 
data = "" 
begin 
    until s.closed? 
    l = s.gets 
    puts "Host:" + l 
    data = data + l 
    end 
rescue Exception => e 
    puts "pp" + e.message 
end 

打印出

Host:a.host.com 
Host:b.host.com 
Host:c.host.com 
Host:Error reading from 3: Connection reset by peer 

應用程序掛起,不知何故。 任何擡頭爲此?奇怪的是,它沒有進入異常處理程序。

+0

如果斷開連接,我想讀取所有已成功讀取的數據。 – Saurajeet

回答