catch non-blocking socket exceptions

Discussion in 'Python' started by Axel Bock, Jun 26, 2003.

  1. Axel Bock

    Axel Bock Guest

    Hi all,

    I try to connect to several hosts at once to verify whether a certain
    service is running. Now it's quite stupid to connect to one after another,
    cause if I do this I'll wait forever if some hosts don't respond (at least
    until TCP timeout).

    But if I connect to several hosts in parallel and use polling objects I'm
    stuck - I don't know how to handle exceptions: are they raised as normal?
    If yes, how do I get the correspondig socket object - or file number?
    If no, how do I know if a socket timed out, or refused connection, or
    something similar?


    Thanks for any hints & greetings,

    Axel.
     
    Axel Bock, Jun 26, 2003
    #1
    1. Advertising

  2. Axel Bock

    Axel Bock Guest

    Am Thu, 26 Jun 2003 17:03:11 +0200 schrieb Axel Bock:

    > Hi all,
    >
    > I try to connect to several hosts at once to verify whether a certain
    > [...blorf...]
    >


    or better still - does someone know how to set the tcp timeout value? THIS
    would greatly simplyfy my task :)


    Thanks again & greetings (again),

    Axel.
     
    Axel Bock, Jun 26, 2003
    #2
    1. Advertising

  3. Axel Bock

    Peter Hansen Guest

    Axel Bock wrote:
    >
    > I try to connect to several hosts at once to verify whether a certain
    > service is running. Now it's quite stupid to connect to one after another,
    > cause if I do this I'll wait forever if some hosts don't respond (at least
    > until TCP timeout).
    >
    > But if I connect to several hosts in parallel and use polling objects I'm
    > stuck - I don't know how to handle exceptions: are they raised as normal?
    > If yes, how do I get the correspondig socket object - or file number?
    > If no, how do I know if a socket timed out, or refused connection, or
    > something similar?


    Check out these pages for some background (especially page four on non-blocking
    sockets):

    http://www.mcmillan-inc.com/sock1.html

    But consider just using Twisted and letting all this stuff be handled
    for you... no sense reinventing the wheel in an area that is notoriously
    difficult to do right.

    -Peter
     
    Peter Hansen, Jun 26, 2003
    #3
  4. Axel Bock

    Axel Bock Guest

    Am Thu, 26 Jun 2003 11:17:02 -0400 schrieb Peter Hansen:

    > Check out these pages for some background (especially page four on
    > non-blocking sockets):
    >
    > http://www.mcmillan-inc.com/sock1.html


    great link :) i forgot about select I admit ...

    > But consider just using Twisted and letting all this stuff be handled
    > for you... no sense reinventing the wheel in an area that is
    > notoriously difficult to do right.


    hm. twisted. yeah.
    I tried it for the udp approach for the same problem, and ended up writing
    the stuff by myself - the udp thing in twisted is rather ... twisted :)
    (and I do not consider the documentation/howtos/examples to be useful for
    beginners in any way).

    for tcp it might be worth a try ... although its really a quite simple
    problem and twisted a rather large solution :)


    thanks,

    axel.
     
    Axel Bock, Jun 26, 2003
    #4
  5. Axel Bock

    Alan Kennedy Guest

    Axel Bock wrote:

    > hm. twisted. yeah.
    > I tried it for the udp approach for the same problem, and ended up
    > writing
    > the stuff by myself - the udp thing in twisted is rather ... twisted :)
    > (and I do not consider the documentation/howtos/examples to be useful for
    > beginners in any way).
    >
    > for tcp it might be worth a try ... although its really a quite simple
    > problem and twisted a rather large solution :)


    Perhaps something like Spread is closer to what you need?

    http://www.python.org/other/spread/

    *Very* easy to get up and running, built for working with UDP, easy to configure
    ......

    Just an alternative suggestion.

    --
    alan kennedy
    -----------------------------------------------------
    check http headers here: http://xhaus.com/headers
    email alan: http://xhaus.com/mailto/alan
     
    Alan Kennedy, Jun 26, 2003
    #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. Hendra Gunawan
    Replies:
    1
    Views:
    12,735
    Allan Herriman
    Apr 8, 2004
  2. Andre Kelmanson

    blocking i/o vs. non blocking i/o (performance)

    Andre Kelmanson, Oct 10, 2003, in forum: C Programming
    Replies:
    3
    Views:
    960
    Valentin Tihomirov
    Oct 12, 2003
  3. Tim Black
    Replies:
    1
    Views:
    1,118
    Alan Kennedy
    Aug 3, 2004
  4. nukleus
    Replies:
    14
    Views:
    850
    Chris Uppal
    Jan 22, 2007
  5. Serge Savoie
    Replies:
    4
    Views:
    281
    Serge Savoie
    Oct 1, 2008
Loading...

Share This Page