Perl AHCMD Server not working

Started by gg4000, May 17, 2012, 06:49:22 PM

Previous topic - Next topic

gg4000

Run the Sever then the client. In the client you can type sendplc a1 on. The server get's it but shows a error. B:(
Anyone see a problem in the code?

Server:

use IO::Socket;
my($housecode,$command,$tmp);
use constant AHCMD => "C:/ahcmd.exe"; #I copied ahcmd.exe to c:/
$tmp = "";
$local = IO::Socket::INET->new(
                Proto     => 'tcp',             
                LocalAddr => '192.168.1.104:6004', 
                      ) or die "$!";
$local->listen();     
$local->autoflush(1);
my $addr;       
while ($addr = $local->accept() ) {     
        print   "Connected from: ", $addr->peerhost(); 
       print   " Port: ", $addr->peerport(), "\n";
              while (<$addr>)
      {       
      $path = "C:/";
      chdir($path) or die "Cant chdir to $path $!";
      my($housecode,$command) = @_;

   print "Sending commands $housecode $command\n";
   print "$_";
      system(AHCMD." sendplc ".$housecode. " " .$command);
      system("AHCMD. $_");
                                     
                print "Received: $_";   
                print $addr $_;         
                print $path $_;                       
                close $addr;
        }
        chomp;                 
       
      if (m/^end/gi) {       
                my $send = "result=$result";   
                print $addr "$send\n";         
                print "Result: $send\n";       
                 }
           print "Closed connection until next command\n";    # Inform that connection
            close $addr;    # close client
}




Client:

use IO::Socket;
$remote = IO::Socket::INET->new(
                Proto   => 'tcp',       
                PeerAddr=> '192.168.1.104',
                PeerPort=> "6004",     
                Reuse   => 1,
                ) or die "$!";
print "Connected to ", $remote->peerhost,
      " on port: ", $remote->peerport, "\n";
$remote->autoflush(1); 
while (<>) {   
        print $remote $_;       
        last if m/^end/gi;     
        my $line = <$remote>;   
        if ($line ne $_) {     
               exit;           
        }
}
my $res = <$remote>;           
$res =~ m/result=(\d*)/gi;     
print "Result: $1\n";           
print "End of client\n";       
close $remote;       

Tuicemen

I'm not  a perl guy but what error is displaying?
Also using AHCMD isn't the best way to pass x10events esspecialy if your planing or releasing this with your app.
AHCMD is known to lock up with repeated events.
Please Read Topic:
General Forum Etiquette
Before you post!

gg4000

Error is....

ActiveScript Error: Expecting SendPLC  [address] [command]

gg4000


Tuicemen

Please Read Topic:
General Forum Etiquette
Before you post!

gg4000

The files are server.exe and client.exe.
The server is set up on 192.168.1.104:8086
The client is just a small test for the server.
Start the server first, then the client.
In the client, you only need to type the house code, the unit number, and the command. A1 ON or a1 on, a1 off.
a1 dim 50, a1 bright 50....etc
Or you can use a browser.
You only need the server to run the X-10 Voice Commander.

To download the server Click Here
To download the test client (Not needed for X10 V.C.)  Click Here

SMF spam blocked by CleanTalk