source: npl/mediabox/lcdproc_edwin/src/clients/examples/iosock.pl @ c5c522c

gcc484ntopperl-5.22
Last change on this file since c5c522c was c5c522c, checked in by Edwin Eefting <edwin@datux.nl>, 8 years ago

initial commit, transferred from cleaned syn3 svn tree

  • Property mode set to 100755
File size: 1.8 KB
Line 
1#!/usr/local/bin/perl -w
2
3use IO::Socket;
4use Fcntl;
5
6# Connect to the server...
7$remote = IO::Socket::INET->new(
8                Proto     => "tcp",
9                PeerAddr  => "localhost",
10                PeerPort  => "13666",
11        )
12        || die "Cannot connect to LCDproc port\n";
13
14# Make sure our messages get there right away
15$remote->autoflush(1);
16
17`sleep 1`;      # Give server plenty of time to notice us...
18
19print $remote "hello\n";
20my $lcdconnect = <$remote>;
21print $lcdconnect;
22
23
24# Turn off blocking mode...
25fcntl($remote, F_SETFL, O_NONBLOCK);
26
27
28# Set up some screen widgets...
29print $remote "client_set name {Test Client (Perl)}\n";
30print $remote "screen_add pings\n";
31print $remote "screen_set pings name {Ping Status}\n";
32print $remote "widget_add pings title title\n";
33print $remote "widget_set pings title {Ping Status}\n";
34print $remote "widget_add pings one string\n";
35print $remote "widget_add pings two string\n";
36print $remote "widget_set pings one 1 2 {Checking machines...}\n";
37
38
39my ($machine, %down, %up, $i, $list);
40
41while(1)
42{
43        #print "Main loop...\n";
44        # Handle input...  (just spew it to the console)
45        while(defined($line = <$remote>)) {
46            print $line;
47        }
48
49        undef %down;
50        undef %up;
51        foreach $machine       ("www.yahoo.com",
52                                "webfoot",
53                                "degas",
54                                "cassat",
55                                "miro",
56                                "monet",
57                                "dali",
58                                "escher",
59                                "seurat",
60                                "rodin",
61                                "matisse",
62                                )
63        {
64                `ping -c 1 $machine`;
65                if($?) { $down{$machine} = 1; }
66                else { $up{$machine} = 1; }
67        }
68        $i = 0;  $list = "";
69        foreach $machine (keys %up)
70        {
71                $i++;
72                $list .= "$machine, ";
73        }
74        print $remote "widget_set pings one 1 2 {Machines Up: $i}\n";
75        $i = 0;  $list = "";
76        foreach $machine (keys %down)
77        {
78                $i++;
79                $list .= "$machine, ";
80        }
81        print $remote "widget_set pings two 1 3 {Down ($i): $list}\n";
82}
83
84close ($remote)            || die "close: $!";
85exit;
Note: See TracBrowser for help on using the repository browser.