Run the Sever then the client. In the client you can type sendplc a1 on. The server get's it but shows a error.
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;