473,386 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 1648
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 (BICouldVeryWellBW).
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_validate(sock):
return True

def ping(host, port, timeout=10.0, validate=default_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(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(timeout)
try:
sock.connect((host, 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 (BICouldVeryWellBW).


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 (BICouldVeryWellBW).


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
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...
5
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...
4
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...
3
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++,...
4
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...
3
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...
6
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...
2
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...
14
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
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,...

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.