Detecting a connection loss && other network questions

Discussion in 'Ruby' started by David Leal, Jul 3, 2008.

  1. David Leal

    David Leal Guest

    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) 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
    --
    Posted via http://www.ruby-forum.com/.
     
    David Leal, Jul 3, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris

    Detecting loss of session

    Chris, Aug 24, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    515
    Kevin Spencer
    Aug 25, 2004
  2. Gordon Beaton
    Replies:
    6
    Views:
    514
  3. Matthew K Jensen

    detecting enabled network interfaces in win32

    Matthew K Jensen, Oct 17, 2004, in forum: Python
    Replies:
    4
    Views:
    479
    Tim Golden
    Oct 18, 2004
  4. Greg Copeland

    DBAPI Loss DB Connection

    Greg Copeland, Apr 2, 2007, in forum: Python
    Replies:
    0
    Views:
    259
    Greg Copeland
    Apr 2, 2007
  5. =?Utf-8?B?cGF0cmlja2RyZA==?=

    Internal connection fatal error and other random db connection err

    =?Utf-8?B?cGF0cmlja2RyZA==?=, Jun 14, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    573
    =?Utf-8?B?cGF0cmlja2RyZA==?=
    Jun 14, 2007
Loading...

Share This Page