Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > How keep python socket alive for ever by setting Keep alive flag.

Reply
Thread Tools

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

 
 
hisan
Guest
Posts: n/a
 
      06-25-2012
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)
 
Reply With Quote
 
 
 
 
Dan Stromberg
Guest
Posts: n/a
 
      06-25-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 <(E-Mail Removed)> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 0 02-01-2009 07:37 AM
socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 1 01-27-2009 05:05 PM
Re: socket.unbind or socket.unlisten? - socket.error: (48,'Address already in use') Jean-Paul Calderone Python 0 01-27-2009 01:41 PM
need a thread to keep a socket connection alive? nephish@xit.net Python 15 04-25-2006 12:42 PM



Advertisments