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

Dan Stromberg drsalists at gmail.com
Mon Jun 25 19:30:41 CEST 2012


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 at 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


More information about the Python-list mailing list