Unlike some others in this thread, I don't think it's impossible to use UDP to send data in two directions: a heartbeat from the client to the server, and data from the server to the client. In fact, I don't see any particular difficulties -- with IP over 30 years old, we have learned to distinguish between source and destination addresses in IP packets (not that this ever was a problem).
You want to do something like the following (untested pseudo code):
... create sockets ...
my @fileno = (fileno(SOCKET1),
fileno(SOCKET2),
fileno(SOCKET3),
fileno(SOCKET4));
my ($rbits, $ebits);
vec($rbits, $_, 1) = 1 for @fileno;
vec($ebits, $_, 1) = 1 for @fileno;
while (1) {
my $time_to_next_heartbeat = ...; # How long till we have to send
+ a hb
if ($time_to_next_heartbeat <= 0) {
... send heartbeats ...
redo;
}
if (select (my $rbits = $rbits, undef, my $ebits = $ebits, $time_t
+o_next_heartbeat)) {
if ($ebits) {
... deal with errors ...
}
if ($rbits) {
foreach my $fileno (@fileno) {
if (vec($rbits, $filen0, 1)) {
... read data ...
}
}
}
}
}
There's a much simpler solution though, and that may work for you:
- Start 4 processes. Each process sends a heart beat every 10 seconds (one process for each of the ports).
- Start another 4 processes. Each of them reads (and logs) whatever it gets from a particular socket.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.