473,466 Members | 4,855 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Socket Help

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
2 1814
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

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: anuradha.k.r | last post by:
hi, i am writing a socket program in python,both client side and server side.I've written the client side which is working perfectly fine(checked it against server program written in C).but as for...
4
by: faktujaa | last post by:
Hi, I am having some problem with callback used in socket implementation. private static void Connect(string strPrtrIPAddr, int intPrtrPort, ref Socket rsocClient) { try { // Create remote end...
9
by: AA | last post by:
This is making me crazy!! Please, if some body can help me. I'm testing a ver simple socket client. In my test I just open and close a connection (in a loop) to my local IIS server (port 80)...
1
by: John Sheppard | last post by:
Thanks to everyone that responded to my previous Socket Programming question. Now I have run into some behavior that I don't quite understand. Programming environment. VS.NET 2003, C#, Windows...
2
by: Droopy | last post by:
Hi, I try to implement a reusable socket class to send and receive data. It seems to work but I have 2 problems : 1) I rely on Socket.Available to detect that the connection is closed (no...
7
by: Colin | last post by:
I'm writing a little console socket server but I'm having some difficulty. Can I ask your advice - where is the best place to get some help on that topic? It would be nice if some people who knew...
2
by: djc | last post by:
I read a network programming book (based on framework 1.1) which indicated that you should 'never' use the RecieveTimeout or the SendTimeout 'socket options' on TCP sockets or you may loose data. I...
6
Sagittarius
by: Sagittarius | last post by:
I will first try to describe my problem in words. I have a simple program, written in C++, that needs to send a single bytearray via a UDP socket to a microprocessor, which returns an answer, also...
3
by: doc | last post by:
What will a flash xml client socket connect to? I have a working php TCP/IP server socket bound to a port >1023 and the flash client will not even connect to it. I can connect to it with non-xml...
1
by: orehian | last post by:
Construct a one-time password system. · Write a server code and a client code. The server code takes as input a username and a one-time password from the client and then sends a message...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.