# Detecting a connection loss && other network questions

**URL:** <https://www.ruby-forum.com/t/detecting-a-connection-loss-other-network-questions/142090>\
**Category:** Ruby\
**Created:** [July 3, 2008, 11:34am UTC](https://www.ruby-forum.com/t/detecting-a-connection-loss-other-network-questions/142090 "2008-07-03T11:34:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![drlelon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ee59a6/32.png) [@drlelon](https://www.ruby-forum.com/u/drlelon)\
**Post date:** [July 3, 2008, 11:34am UTC](https://www.ruby-forum.com/t/detecting-a-connection-loss-other-network-questions/142090/1 "2008-07-03T11:34:18Z")

</div>

Hello all,

I’m trying to get acquainted with network programming in Ruby and I’m  
facing several problems. The biggest 2 are

1. How do I detect a connection loss when it happens while the client is  
blocking, waiting for data? According to Stevens, most tcp  
implementations time out after 11 minutes, but I disconnected my cable  
and waited long after that–nothing. Is this my fault? Is it a ruby  
problem?

2. The client (an IRC bot) seems to be stuck sometimes. Suddenly, input  
stops, it stops logging data, everything stops. This happens on a  
particular IRC server ([heinlein.freenode.net](http://heinlein.freenode.net)) in the middle of the MOTD,  
but happened a few days ago on another server during normal usage. The  
code I’m using is

buffer = @socket.recvfrom(512).first  
messages = buffer.split /\n/

@messages.last \<\< messages.shift   
if @messages.last && @messages.last[-1] != ?\r

@messages += messages

An interesting twist is that this doesn’t happen on heinlein upon  
connection if I print the contents of the array I get from recvfrom.  
Seems to be some kind of flushing problem, but I don’t know enough about  
it to be sure.

Any ideas?

Cheers,

David
