[c5c522c] | 1 | #!/usr/local/bin/perl -w |
---|
| 2 | |
---|
| 3 | # |
---|
| 4 | # This is just a test! It's simple, cheesy, and doesn't do much |
---|
| 5 | # or even look very nice. |
---|
| 6 | # |
---|
| 7 | # However, it demonstrates one way to handle input from the server. |
---|
| 8 | # (although it seems buggy.. oops! :) |
---|
| 9 | # |
---|
| 10 | |
---|
| 11 | use IO::Socket; |
---|
| 12 | use Fcntl; |
---|
| 13 | |
---|
| 14 | # Connect to the server... |
---|
| 15 | $remote = IO::Socket::INET->new( |
---|
| 16 | Proto => "tcp", |
---|
| 17 | PeerAddr => "localhost", |
---|
| 18 | PeerPort => "13666", |
---|
| 19 | ) |
---|
| 20 | || die "Cannot connect to LCDproc port\n"; |
---|
| 21 | |
---|
| 22 | # Make sure our messages get there right away |
---|
| 23 | $remote->autoflush(1); |
---|
| 24 | |
---|
| 25 | sleep 1; # Give server plenty of time to notice us... |
---|
| 26 | |
---|
| 27 | print $remote "hello\n"; |
---|
| 28 | my $lcdconnect = <$remote>; |
---|
| 29 | #print $lcdconnect; |
---|
| 30 | |
---|
| 31 | |
---|
| 32 | # Turn off blocking mode... |
---|
| 33 | fcntl($remote, F_SETFL, O_NONBLOCK); |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | # Set up some screen widgets... |
---|
| 37 | print $remote "client_set name {X11AMP test}\n"; |
---|
| 38 | print $remote "screen_add x11amp\n"; |
---|
| 39 | print $remote "screen_set x11amp name {X11AMP test}\n"; |
---|
| 40 | print $remote "widget_add x11amp title title\n"; |
---|
| 41 | print $remote "widget_set x11amp title {X11AMP test}\n"; |
---|
| 42 | print $remote "widget_add x11amp one string\n"; |
---|
| 43 | print $remote "widget_set x11amp one 1 2 { <-: E ; F :->}\n"; |
---|
| 44 | |
---|
| 45 | |
---|
| 46 | while(1) |
---|
| 47 | { |
---|
| 48 | # Handle input... |
---|
| 49 | while(defined($line = <$remote>)) { |
---|
| 50 | @items = split(" ", $line); |
---|
| 51 | $command = shift @items; |
---|
| 52 | # Use input to change songs... |
---|
| 53 | if($command eq "key") |
---|
| 54 | { |
---|
| 55 | $key = shift @items; |
---|
| 56 | if($key eq "E") |
---|
| 57 | { |
---|
| 58 | system("x11amp --rew"); |
---|
| 59 | } |
---|
| 60 | if($key eq "F") |
---|
| 61 | { |
---|
| 62 | system("x11amp --fwd"); |
---|
| 63 | } |
---|
| 64 | } |
---|
| 65 | # And ignore everything else |
---|
| 66 | elsif($command eq "connect") |
---|
| 67 | { |
---|
| 68 | } |
---|
| 69 | elsif($command eq "listen") |
---|
| 70 | { |
---|
| 71 | } |
---|
| 72 | elsif($command eq "ignore") |
---|
| 73 | { |
---|
| 74 | } |
---|
| 75 | else { |
---|
| 76 | if($line =~ /\S/) {print "Huh? $line\n";} |
---|
| 77 | } |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | sleep 1; |
---|
| 81 | |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | close ($remote) || die "close: $!"; |
---|
| 85 | exit; |
---|