Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #24435 > unrolled thread

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

Started byhisan <santosh.ssit@gmail.com>
First post2012-06-25 10:21 -0700
Last post2012-06-25 17:30 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  How keep python socket alive for ever by setting Keep alive flag. hisan <santosh.ssit@gmail.com> - 2012-06-25 10:21 -0700
    Re: How keep python socket alive for ever by setting Keep alive flag. Dan Stromberg <drsalists@gmail.com> - 2012-06-25 17:30 +0000

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

Fromhisan <santosh.ssit@gmail.com>
Date2012-06-25 10:21 -0700
SubjectHow keep python socket alive for ever by setting Keep alive flag.
Message-ID<44c35921-ff32-4e80-b8fd-4dd2f3960a21@googlegroups.com>
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)

[toc] | [next] | [standalone]


#24436

FromDan Stromberg <drsalists@gmail.com>
Date2012-06-25 17:30 +0000
Message-ID<mailman.1492.1340645444.4697.python-list@python.org>
In reply to#24435
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 <santosh.ssit@gmail.com> 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 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)
> --
> http://mail.python.org/mailman/listinfo/python-list

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web