RE: Newbie question: SOLVED (how to keep a socket listening), but still some questions

Discussion in 'Python' started by Giovanni Tumiati, Jun 25, 2005.

  1. To all those that replied - thank you.
    I solved the problem I posted earlier.
    I'm embarrassed to admit that it was caused by the following:
    ....
    while 1: ## wait for a connection
    try:
    #...waiting for connection
    (client, address)=sa.accept()
    except sa.timeout: <--------------there is no such exception for a socket!
    #...waiting for connection timeout
    continue
    except:
    continue ## for now ignore this!
    ....

    There is no "timeout exception" on a socket so the exception was failing.
    I don't remember where I read about it, but now I cannot find such an
    exception...I guess I dreamt it up :)

    However some of my questions still remain from earlier post:
    (1) What is the difference between / how should they be used?
    - setdefaulttimeout(timeout)
    - settimeout(value)

    (2)Does one have to do a socket.shutdown() before one does a socket.close??

    Again thanks!
    pete
    Giovanni Tumiati, Jun 25, 2005
    #1
    1. Advertising

  2. Giovanni Tumiati

    Peter Hansen Guest

    Re: Newbie question: SOLVED (how to keep a socket listening), butstill some questions

    Giovanni Tumiati wrote:
    > However some of my questions still remain from earlier post:
    > (1) What is the difference between / how should they be used?
    > - setdefaulttimeout(timeout)
    > - settimeout(value)


    I think it's basically as you surmised. Calling
    socket.setdefaulttimeout() (where "socket" is the module itself) sets up
    the default timeout value for all subsequently created sockets. Calling
    sock.settimeout() (where "sock" is a specific socket object) changes the
    timeout value on that socket alone.

    > (2)Does one have to do a socket.shutdown() before one does a socket.close??


    Not normally, AFAIK.

    -Peter
    Peter Hansen, Jun 25, 2005
    #2
    1. Advertising

  3. On 2005-06-25, Giovanni Tumiati <> wrote:

    > However some of my questions still remain from earlier post:
    > (1) What is the difference between
    > - setdefaulttimeout(timeout)


    That sets the timeout for any sockets created in the future.

    > - settimeout(value)


    That sets the timeout for an individual socket.

    > how should they be used?


    Use the former if you want the same timeout for all sockets.
    Use the latter if if you want to set them individually for each
    socket.

    Is the documentation unclear?

    > (2)Does one have to do a socket.shutdown() before one does a
    > socket.close??


    No.

    [I've never figured out why one would do a shutdown RDWR
    rather than close the connection, but I haven't put a lot of
    thought into it.]

    --
    Grant Edwards grante Yow! -- I love KATRINKA
    at because she drives a
    visi.com PONTIAC. We're going
    awaynow. I fed the cat.
    Grant Edwards, Jun 25, 2005
    #3
    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. pwilkins
    Replies:
    7
    Views:
    437
    Grant Edwards
    Jun 25, 2005
  2. Jp Calderone
    Replies:
    1
    Views:
    338
    Grant Edwards
    Jun 25, 2005
  3. Jp Calderone
    Replies:
    2
    Views:
    382
    Grant Edwards
    Jun 25, 2005
  4. Michael Bacarella
    Replies:
    26
    Views:
    1,313
    harri
    Nov 20, 2007
  5. hisan
    Replies:
    1
    Views:
    1,301
    Dan Stromberg
    Jun 25, 2012
Loading...

Share This Page