Files
lcdproc/clients/examples/iosock.pl
T
William Ferrell 6dabd0b8f3 Applied patches supplied by Andre' Breiler:
- bugfixes for display != MatrixOrb LCD
	- changes the meaning of output_state
		+ it's now a bitfield where evry bit corresponds to
		  one output
	- protocol change
		output on|off|value
		where on    = all outputs on
		      off   = all outputs off
		      value = output on for all 1 bits
	- changes the behavior for key presses
	  Keypresses are now deliverd to _all_ clients (not only
	  the one with the active screen)
	reason: I have an client which is only active a few seconds after
                an keypress
	- changes the protocol so that a response is sent for every
	  command
	reason: the client needs to communicate with the server with a
                minimal latency
2001-03-22 22:51:49 +00:00

87 lines
1.8 KiB
Perl
Executable File

#!/usr/local/bin/perl -w
use IO::Socket;
use Fcntl;
# Connect to the server...
$remote = IO::Socket::INET->new(
Proto => "tcp",
PeerAddr => "localhost",
PeerPort => "13666",
)
|| die "Cannot connect to LCDproc port\n";
# Make sure our messages get there right away
$remote->autoflush(1);
`sleep 1`; # Give server plenty of time to notice us...
print $remote "hello\n";
my $lcdconnect = <$remote>;
print $lcdconnect;
# Turn off blocking mode...
fcntl($remote, F_SETFL, O_NONBLOCK);
# Set up some screen widgets...
print $remote "client_set name {Test Client (Perl)}\n";
print $remote "screen_add pings\n";
print $remote "screen_set pings name {Ping Status}\n";
print $remote "widget_add pings title title\n";
print $remote "widget_set pings title {Ping Status}\n";
print $remote "widget_add pings one string\n";
print $remote "widget_add pings two string\n";
print $remote "widget_set pings one 1 2 {Checking machines...}\n";
my ($machine, %down, %up, $i, $list);
while(1)
{
#print "Main loop...\n";
# Handle input... (just spew it to the console)
while(defined($line = <$remote>)) {
if ( $line =~ /^success$/ ) next;
print $line;
}
undef %down;
undef %up;
foreach $machine ("ZakaZak",
"webfoot",
"degas",
"cassat",
"miro",
"monet",
"dali",
"escher",
"seurat",
"rodin",
"matisse",
)
{
`ping -c 1 $machine`;
if($?) { $down{$machine} = 1; }
else { $up{$machine} = 1; }
}
$i = 0; $list = "";
foreach $machine (keys %up)
{
$i++;
$list .= "$machine, ";
}
print $remote "widget_set pings one 1 2 {Machines Up: $i}\n";
$i = 0; $list = "";
foreach $machine (keys %down)
{
$i++;
$list .= "$machine, ";
}
print $remote "widget_set pings two 1 3 {Down ($i): $list}\n";
}
close ($remote) || die "close: $!";
exit;