How keep python socket alive for ever by setting Keep alive flag.

Discussion in 'Python' started by hisan, Jun 25, 2012.

  1. hisan

    hisan Guest

    Hi All,

    I want to open a socket connection and keep it alive for ever or until i explicitly close the socket connection.

    below is my code though i have set keep alive flag the socket gets closed after some time .please help me out here

    sb_sock = socket.socket(socket.AF_INET,
    socket.SOCK_STREAM,socket.SOL_TCP)
    sb_sock.setsockopt( socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
    sb_sock.connect((msg_host, host_port))
    sb_sock.send(reg_msg)
     
    hisan, Jun 25, 2012
    #1
    1. Advertising

  2. http://www.unixguide.net/network/socketfaq/4.7.shtml

    It's better to add the ability to recreate a socket if it encounters
    trouble. SO_KEEPALIVE is there to help you detect if the other end of
    your connection has disappeared.

    Network programming has relatively few absolutes - it's best to build
    in error checking and sometimes, error responses that go beyond mere
    error messages.

    On Mon, Jun 25, 2012 at 5:21 PM, hisan <> wrote:
    > Hi All,
    >
    > I want to open a socket connection and keep it alive for ever or until i explicitly close the socket connection.
    >
    > below is my code though i have set keep alive flag the socket gets closedafter some time .please help me out here
    >
    >            sb_sock = socket.socket(socket.AF_INET,
    > socket.SOCK_STREAM,socket.SOL_TCP)
    >            sb_sock.setsockopt( socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
    >            sb_sock.connect((msg_host, host_port))
    >            sb_sock.send(reg_msg)
    > --
    > http://mail.python.org/mailman/listinfo/python-list
     
    Dan Stromberg, Jun 25, 2012
    #2
    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. Luiz Alberto Gibson da Costa

    web chat development, http header connection: keep-alive

    Luiz Alberto Gibson da Costa, Aug 6, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    634
    Luiz Alberto Gibson da Costa
    Aug 6, 2003
  2. Replies:
    15
    Views:
    4,045
  3. Shannon
    Replies:
    6
    Views:
    544
    Mike Treseler
    Jun 18, 2009
  4. Wes McKinney
    Replies:
    3
    Views:
    929
    Irmen de Jong
    Sep 17, 2009
  5. Jason
    Replies:
    0
    Views:
    227
    Jason
    Jul 6, 2004
Loading...

Share This Page