Socket timeout

Discussion in 'Ruby' started by Lee Jarvis, Nov 12, 2007.

  1. Lee Jarvis

    Lee Jarvis Guest

    I am using a TCPSocket and I want the script to restart if the
    connection times out. I have tried doing it myself and searched around
    everywhere for a solution but I have had no luck.. Any help would be
    great

    tia

    Lee
    --
    Posted via http://www.ruby-forum.com/.
    Lee Jarvis, Nov 12, 2007
    #1
    1. Advertising

  2. Note: parts of this message were removed by the gateway to make it a legal Usenet post.

    On 11/11/07, Lee Jarvis <> wrote:
    >
    > I am using a TCPSocket and I want the script to restart if the
    > connection times out. I have tried doing it myself and searched around
    > everywhere for a solution but I have had no luck.. Any help would be
    > great




    What do you mean by "the connection times out"? Do you mean that the
    connection has no read or write activity for some interval of time?

    If you need to do that, then the Ruby/EventMachine library has that ability.
    You'll need to rearrange your code to go this route, so perhaps someone else
    will have a less invasive solution. If not, then look at EventMachine.
    Francis Cianfrocca, Nov 12, 2007
    #2
    1. Advertising

  3. Lee Jarvis

    Lee Jarvis Guest

    Francis Cianfrocca wrote:
    > What do you mean by "the connection times out"? Do you mean that the
    > connection has no read or write activity for some interval of time?

    Yes, basically


    > If you need to do that, then the Ruby/EventMachine library has that
    > ability.
    > You'll need to rearrange your code to go this route, so perhaps someone
    > else
    > will have a less invasive solution. If not, then look at EventMachine.


    Uh, I am editing an old program of mine which is quite large, about
    1.4k+ lines, so I am trying to do it the least invasive way possible.. I
    appreciate your input so quickly though. Perhaps this is the only route.

    Lee
    --
    Posted via http://www.ruby-forum.com/.
    Lee Jarvis, Nov 12, 2007
    #3
  4. Lee Jarvis <> writes:

    Q> Francis Cianfrocca wrote:
    >> What do you mean by "the connection times out"? Do you mean that the
    >> connection has no read or write activity for some interval of time?

    > Yes, basically



    You can adjust the SO_RCVTIMEO and SO_SNDTIMEO socket options using
    Socket#{get,set}sockopts.

    However, they are susceptible to trickle attack. For example, if you
    set the receive timeout to 30 seconds, then the sender can send just
    one packet every 30 seconds, tying up resources on your end.

    The proper solution requires application-level enforcement of
    timeout. You can use the timeout library for the least invasive
    mechanism to even changing the core mechanism to Ruby/EventMachine.


    YS.



    >
    >
    >> If you need to do that, then the Ruby/EventMachine library has that
    >> ability.
    >> You'll need to rearrange your code to go this route, so perhaps someone
    >> else
    >> will have a less invasive solution. If not, then look at EventMachine.

    >
    > Uh, I am editing an old program of mine which is quite large, about
    > 1.4k+ lines, so I am trying to do it the least invasive way possible.. I
    > appreciate your input so quickly though. Perhaps this is the only route.
    >
    > Lee
    > --
    > Posted via http://www.ruby-forum.com/.
    Yohanes Santoso, Nov 12, 2007
    #4
  5. Lee Jarvis

    Roger Pack Guest

    If you're not worried about scaling then
    Timeout::timeout(30) {
    do stuff }

    or
    Thread.new {
    sleep 30
    if hasnt_done_anything
    raise on it # scary!
    end
    }

    maybe :)

    Lee Jarvis wrote:
    > I am using a TCPSocket and I want the script to restart if the
    > connection times out. I have tried doing it myself and searched around
    > everywhere for a solution but I have had no luck.. Any help would be
    > great
    >
    > tia
    >
    > Lee


    --
    Posted via http://www.ruby-forum.com/.
    Roger Pack, Nov 12, 2007
    #5
    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. p.
    Replies:
    4
    Views:
    594
    Giampaolo Rodola'
    Jan 10, 2009
  2. Laszlo Nagy
    Replies:
    1
    Views:
    4,822
    Mark Wooding
    Jan 27, 2009
  3. Jean-Paul Calderone
    Replies:
    0
    Views:
    966
    Jean-Paul Calderone
    Jan 27, 2009
  4. Laszlo Nagy
    Replies:
    0
    Views:
    545
    Laszlo Nagy
    Feb 1, 2009
  5. Mark Probert

    Timeout::timeout and Socket timeout

    Mark Probert, Oct 6, 2004, in forum: Ruby
    Replies:
    1
    Views:
    1,283
    Brian Candler
    Oct 6, 2004
Loading...

Share This Page