I have "collected" the code for a simple UDP server and modified it to my needs:
#!/usr/bin/perl; #use strict; use warnings; use IO::Socket::INET; my $server='192.168.178.6'; my $port='50099'; my $user='monitor'; my $pass='monitor'; $sock = IO::Socket::INET->new(PeerAddr => $server, PeerPort => $port, Proto => 'udp') or die("ERROR open Socket $server:$port ( +$@)\n"); $sock->autoflush(1); my($in, $buf, $kid, $count); die "fork fail: $!" unless defined($kid = fork); if ($kid) { print $sock "login monitor monitor"; select(undef, undef, undef, 0.5); #sleep 0.5s print $sock "log on"; select(undef, undef, undef, 0.5); print $sock "status"; while(1) { print $sock "log on"; sleep(10); }; # kill the child process #kill(TERM => $kid); } else { while(1) { $buf = <$sock>; print $buf; if ($buf =~ m/.*Nat.*/) { $count++; print "Count $count"; }; }; close $sock; }

The "$kid" logs on to an UDP server application and in the while loop makes sure that the connection does not time out. The "else" part constantly monitors the server output and has some rules (here simplified example) that react to the output.

Now I want to send further commands, similar to the "log on" in the while loop. They shall be based on timers and/or reactions to the parsed output of the server.

Any help to my meagre Perl skills would be really appreciated.


In reply to Timers in an UDP Client by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.