Skip to content
Snippets Groups Projects
Commit e5d41a1e authored by Duncan White's avatar Duncan White
Browse files

realised that command-listener needs to take one line of input - additional...

realised that command-listener needs to take one line of input - additional command line arguments for the command to be run, similarly the command-client needs to pass that line..
parent 31179d84
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use IO::Socket;
my $host = shift @ARGV || "146.169.22.26"; # shell4..
my $port = 55001;
#
# my $socket = connect_server();
# connect to our server (trying several times if
# necessary), return the socket we receive.
# In case of repeated failure, return undef.
#
sub connect_server()
{
warn "trying to connect to $host:$port\n";
foreach (1..5) {
my $socket = new IO::Socket::INET('PeerAddr' => $host,
'PeerPort' => $port,
'Proto' => 'tcp');
return $socket if $socket;
warn "trying again...\n";
sleep 1;
}
return undef;
}
my $socket = connect_server();
die "can't connect to $host:$port\n" unless $socket;
warn "connected to $host..\n";
my $line = join( " ", @ARGV );
print $socket "$line\n";
while( <$socket> )
{
print;
}
#!/usr/bin/perl
#
# command-listener: daemon that listens for a connection on a
# port and runs a single specific command, sending the
# port, reads a single line of text (arguments) and runs a single
# specific command with those arguments, gathering and sending the
# results of running that command back to the client.
#
use strict;
......@@ -18,7 +19,7 @@ use csglib::Log;
my $logfile = "/tmp/command-listener.log";
# command to run..
my $command = "/bin/date"; # example:-)
my $command = "/bin/ls"; # example:-)
my $port = shift @ARGV || 55001;
my $quit = 0;
......@@ -110,7 +111,16 @@ sub connection_loop ($$)
#
sub converse ()
{
system( $command );
$log->warn( "reading line from client" );
my $args = <STDIN>;
unless( $args )
{
$log->warn( "converse: eof from client" );
print "client: gimme some args:-)\n";
return;
}
chomp $args;
system( "$command $args" );
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment