473,804 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

heartbeats

Hi,

I need to write a heartbeat solution to monitor some external clients,
and what is different as in the examples that I have seen so far is that
I want my central server to poll the clients, and not the clients
"pinging" the central server.

In detail I need a daemon on my central server which e.g. which in a
loop pings (not really ping but you know what I mean) each 20 seconds
one of the clients.

The only thing the client has to do is to accept the connection.
(optionally sending back some bytes). If it refuses it is assumed to be
offline.

My central server, and this is important, should have a short timeout.
If one client does not respond because it's offline, after max. 10
seconds the central server should continue with the next client.
Which python functions would be the most convenient for this application?

Best regards,
Yves
Dec 9 '05 #1
4 1684
Yves Glodt enlightened us with:
In detail I need a daemon on my central server which e.g. which in a
loop pings (not really ping but you know what I mean) each 20
seconds one of the clients.
You probably mean "really a ping, just not an ICMP echo request".
The only thing the client has to do is to accept the connection.
(optionally sending back some bytes). If it refuses it is assumed to
be offline.
Ok, fair enough.
My central server, and this is important, should have a short
timeout. If one client does not respond because it's offline, after
max. 10 seconds the central server should continue with the next
client.


I'd write a single function that pings a client and waits for a
response/timeout. It then should return True if the client is online,
and False if it is offline. You can then use a list of clients and the
filter() function, to retrieve a list of online clients.

Sybren
--
The problem with the world is stupidity. Not saying there should be a
capital punishment for stupidity, but why don't we just take the
safety labels off of everything and let the problem solve itself?
Frank Zappa
Dec 9 '05 #2
On Fri, 9 Dec 2005, Sybren Stuvel wrote:
Yves Glodt enlightened us with:
In detail I need a daemon on my central server which e.g. which in a
loop pings (not really ping but you know what I mean) each 20 seconds
one of the clients.
Do you mean pings one client every 20 sec, or each client every 20 sec?
You probably mean "really a ping, just not an ICMP echo request".


What's a real ping, if not an ICMP echo request? That's pretty much the
definitive packet for internetwork groping as far as i know. I think that
the more generic sense of ping is a later meaning (BICouldVeryWel lBW).
My central server, and this is important, should have a short timeout.
If one client does not respond because it's offline, after max. 10
seconds the central server should continue with the next client.


I'd write a single function that pings a client and waits for a
response/timeout. It then should return True if the client is online,
and False if it is offline. You can then use a list of clients and the
filter() function, to retrieve a list of online clients.


That sounds like a good plan.

To do the timeouts, you want the settimeout method on socket:

import socket

def default_validat e(sock):
return True

def ping(host, port, timeout=10.0, validate=defaul t_validate):

"""Ping a specified host on the specified port. The timeout (in
seconds) and a validation function can be set; the validation
function should accept a freshly opened socket and return True if
it's okay, and False if not. This functions returns True if the
specified target can be connected to and yields a valid socket, and
False otherwise.

"""
sock = socket.socket(s ocket.AF_INET, socket.SOCK_STR EAM)
sock.settimeout (timeout)
try:
sock.connect((h ost, port))
except socket.error:
return False
ok = validate(sock)
sock.close()
return ok

A potential problem with this is that in the worst case, you'll be
spending a little over ten seconds on each socket; if you have a lot of
sockets, that might mean you're not getting through them fast enough.
There are two ways round this: handle several pings in parallel using
threads, or use non-blocking sockets to handle several at once with a
single thread.

tom

--
everything from live chats and the Web, to the COOLEST DISGUSTING
PORNOGRAPHY AND RADICAL MADNESS!!
Dec 9 '05 #3
Tom Anderson wrote:
On Fri, 9 Dec 2005, Sybren Stuvel wrote:
You probably mean "really a ping, just not an ICMP echo request".


What's a real ping, if not an ICMP echo request? That's pretty much the
definitive packet for internetwork groping as far as i know. I think that
the more generic sense of ping is a later meaning (BICouldVeryWel lBW).


Submarines came before the 'net. ;-)

Dec 9 '05 #4
On Fri, 9 Dec 2005, Peter Hansen wrote:
Tom Anderson wrote:
On Fri, 9 Dec 2005, Sybren Stuvel wrote:
You probably mean "really a ping, just not an ICMP echo request".


What's a real ping, if not an ICMP echo request? That's pretty much the
definitive packet for internetwork groping as far as i know. I think that
the more generic sense of ping is a later meaning (BICouldVeryWel lBW).


Submarines came before the 'net. ;-)


Ah, of course!

if self.ping(host) :
self.depth = PERISCOPE_DEPTH
periscope.up()
self.tubes["bow"].load()

:)

tom

--
Rip and tear your guts! You are huge! That means you have huge guts! Rip
and tear! -- The Doomguy
Dec 9 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
950
by: GMane Python | last post by:
Hello Everyone. Whil e reading the Python Cookbook as a means of learning Python, I came across the script by Nicola Larosa. Not knowing anything about PERL, I was wondering if there were a translation in PERL so I could have my Netware servers send heartbeats to the heartbeat server? Thanks! Dave
5
9905
by: Rene | last post by:
Suddenly in one database we have a lot of errors, it seams some things are corrupted. I tried to start maintanance / database repair, but this fails too. When selecting in Query Analyzer a range of records from a table I get the following message: Location: p:\sql\ntdbms\storeng\drs\include\record.inl:1447 Expression: m_SizeRec > 0 && m_SizeRec <= MAXDATAROW SPID: 68
4
1890
by: bwmiller16 | last post by:
Folks - Again, a three-peat: RH AS3, UDB 8.1.7 on one pair of x-series, 8.1.8 on 2 i86 test boxes... We were just about to put all we had into production and now we're unable to get HADR to work consistently; we get congested-status even though we have a giggy-net that's very fast (we are able to SSH copy between our production servers at about 30mb/second, encrypted).
3
1422
by: Tal Shachar | last post by:
Hi All, I posted this request on ...dotnet.framework.interop newsgroup, but I thought to try also here, and ask to get your inputs for the following issue: I have an application written in C++, and now I'm going to add another module to it, which I'm going to write in C#, and wrap it as a COM. The new module is going to interact with the existing application during runtime (call the application's methods and run some BL according to the...
4
9225
by: Vlad Hrybok | last post by:
I am using Application_End to send out a notification about application being unloaded. I found that those notifications are not being sent because the app seems to get unloaded without Application_End ever being called. We started logging Application_Start and Application_End events and found that the number is not even: Application_Start happen more often than Application_End. My question is: What are the sutuations in which we should...
3
2111
by: Court Jester | last post by:
Hi all, Excuse me if this is wrong forum for this but I've implemented a protocol handler for my socket server using the state pattern and it works fine until I attempt to introduce heartbeats which are sent independently of the client process on the same socket to the server. Now the state can be processing commands and finds that it has received a message for the client and this contravenes the protocol and state transition is...
6
5165
by: dredge | last post by:
Hi, the server that hosts my PHP pages has its clock set to Greenwich Mean Time (GMT timezone 0). I need for my PHP scripts to have access to my local time which is Central Standard Time in the U.S. (CST timezone -6). Note: daylight savings time _is_ observed in my state. I have looked all over a PHP algorithm that would convert GMT to CST but have so far not been successful. Does anyone have such an algorithm lying around that they could...
2
4343
by: dougmcmurtry | last post by:
I have an Asynchronous socket that sends data to a server for credit card approvals. The socket is kept alive by the server through a heartbeat that sends a "beat" every 90 seconds. Trouble is that the network is unreliable at times and thus the server will drop my connection from time to time. I need to code around this so I can reconnect to the server whenever this happens. THE PROBLEM: The Connected, Poll, and Available properties...
14
6093
by: imran akhtar | last post by:
Hi. I have created a program which works correctly, and was just wondering if someone could help me in writing another program which works in the same way, but if the code is different. Below is what the program has to do: This is the program I have created: print "--------Welcome To The Heartbeat Program--------" averagerate = input ("\nPlease enter your average heart rate:")
0
9711
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9593
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10595
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10343
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10088
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6862
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5529
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4306
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 we have to send another system
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.