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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.