Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/env perl use IO::Socket; use strict; my $socket = new IO::Socket::INET ( PeerAddr => $_, PeerPort => '7071', Proto => 'tcp', ); die "Coudn't open socket" unless $socket; $socket->autoflush(1); my $dir = "/tmp"; print $socket "ls:$dir\n"; close($socket);
#!/usr/bin/env perl # perl modules use IO::Socket; use POSIX qw(:sys_wait_h); use Sys::Hostname; my $hostname = hostname; my $port = "7071"; $SIG{CHLD} = 'IGNORE'; # make socket connection my $socket = new IO::Socket::INET ( LocalHost => "$hostname", LocalPort => "$port", Proto => 'tcp', Reuse => 1, Listen => SOMAXCONN, ); die "Could not create socket: $!\n" unless $socket; while ($client = $socket->accept()) { $client->autoflush(1); while (<$client>) { chomp; my ($command,@var2) = split(":", $_); my $cmd; $pid = fork; if ($pid == 0){ } else { `kill $pid 2>/dev/null`; } unless ( $pid ){ if ($command eq 'ls'){ $cmd = sprintf("ls -s @var"); } $run_cmd = system($cmd); } } close($client); } close($socket);
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: socket help
by ikegami (Patriarch) on Feb 14, 2011 at 02:44 UTC | |
by Anonymous Monk on Feb 14, 2011 at 14:11 UTC | |
by ikegami (Patriarch) on Feb 14, 2011 at 16:08 UTC | |
Re: socket help
by snoopy (Curate) on Feb 14, 2011 at 02:30 UTC | |
by Anonymous Monk on Feb 14, 2011 at 02:47 UTC | |
Re: socket help
by Anonymous Monk on Feb 14, 2011 at 00:44 UTC | |
by Anonymous Monk on Feb 14, 2011 at 01:16 UTC | |
by Anonymous Monk on Feb 14, 2011 at 01:22 UTC |