how to know if socket is still connected

Grant Edwards grante at visi.com
Sun Jul 16 21:06:09 EDT 2006


On 2006-07-16, nephish at xit.net <nephish at xit.net> wrote:

>> If the server has closed the connection, then a recv() on the
>> socket will return an empty string "", and a send() on the
>> socket will raise an exception.

> like this ?
> databack = aeris_sockobj.recv(2048)
>  if databack:
>             view_msg = 'caught request acknowlage %s bytes \n' %
> len(databack)
> else:
>             view_msg = 'fail to recieve data from aeris server\n'
>
> then put the reconnect in the else: block ?

Yes, if the problem is that the host closes the connection,
that should work.  Modulo the broken indentation and
line-wrapping. ;)

-- 
Grant Edwards                   grante             Yow!  My mind is a potato
                                  at               field...
                               visi.com            



More information about the Python-list mailing list