By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,767 Members | 1,375 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,767 IT Pros & Developers. It's quick & easy.

Socket Help

P: n/a
Hello-

I have a python routine (Python 2.2.3 on Windows 2000 "Professional") using
a socket connection. Problem is, the backend service I'm connecting to will
hang every so often and the socket will simply wait for a response which
will never come. I'm thinking of putting in a routine to check the socket's
status, which now brings in threading. Before I go to the trouble I thought
I'd ask if there is a simple way to verify my socket is still communicating.
It's running about 200 transactions per second...if I put in the threaded
timer I'd have it take a look every few seconds to see if the
"TotalRecordsProcessed" counter has been incremented.

Your constructive thoughts are requested.

Thanks!

--greg

************************************************** ********************
The information contained in this communication is
confidential, is intended only for the use of the recipient
named above, and may be legally privileged.
If the reader of this message is not the intended
recipient, you are hereby notified that any dissemination,
distribution, or copying of this communication is strictly
prohibited.
If you have received this communication in error,
please re-send this communication to the sender and
delete the original message or any copy of it from your
computer system. Thank You.
Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Lindstrom Greg - glinds <Gr************@acxiom.com> wrote in message news:<ma*************************************@pyth on.org>...

I'd ask if there is a simple way to verify my socket is still communicating.


how about this, taken from a non-blocking socket class's Connect method:

class NBSocket:
def __init__(self):
self.__host = 'localhost'
self.__port = 177
self.__myconnection = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
self.__myconnection.setsockopt(0,socket.SO_KEEPALI VE,1)
self.__connected = 0
return

def connect(self, host = 'localhost', port = 177, applicationName = 'NBSocket'):
"""
================================================== ====================c+
NBSocket.connect(self,host,port,applicationName)

This procedure opens the connection to the socket defined in __init__
it takes the host name, prot number and application name as aruguments
host defaults to localhost
port defaults to 177
application name defaults to None
It tries to connect once and if it doesn't get a response after 5
seconds or if it can't connect right away it raises a socket.error
exception
================================================== ====================c-
"""
# Test to see if we are already connected
if self.__connected:
print "This socket is already connected"
return 1
self.__host = host
self.__port = int(port)
self.__applicationName = applicationName
counter = 0
try:

failed = 1
while failed:
try:
self.__myconnection.recv(1024)
self.__connected = 1
self.__myconnection.setblocking(1)
failed = 0
print 'connected'
except socket.error:
print 'unable to connect'
counter = counter + 1
time.sleep(1)
if counter > 5:
raise
except socket.error:
raise

then continue on with your communication with the server...

cheers,
S
Jul 18 '05 #2

P: n/a

Python 2.3 has support for timeout on sockets.

l.f.

On Mon, 29 Mar 2004, Lindstrom Greg - glinds wrote:
Hello-

I have a python routine (Python 2.2.3 on Windows 2000 "Professional") using
a socket connection. Problem is, the backend service I'm connecting to will
hang every so often and the socket will simply wait for a response which
will never come. I'm thinking of putting in a routine to check the socket's
status, which now brings in threading. Before I go to the trouble I thought
I'd ask if there is a simple way to verify my socket is still communicating.
It's running about 200 transactions per second...if I put in the threaded
timer I'd have it take a look every few seconds to see if the
"TotalRecordsProcessed" counter has been incremented.

Your constructive thoughts are requested.


--------------------------------------------------------------------------
-- ) Luca Fini Tel: +39 055 2752 307
___ |\ INAF - Oss. Astrofisico di Arcetri Fax: +39 055 2752 292
/ | | |-_ L.go E.Fermi, 5 +-----------------------------------------
(___|___//___) 50125 Firenze / WWW: http://www.arcetri.astro.it/~lfini
(_) (_) Italia / e-mail: lf***@arcetri.astro.it
-----------------------------+--------------------------------------------
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.