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

H

hisan

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)
 
D

Dan Stromberg

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top