clone4 has asked for the wisdom of the Perl Monks concerning the following question:
use IO::Socket; $sock = IO::Socket::INET->new ( Localhost => 'localhost', LocalPort => '18080', Proto => 'tcp', Listen => 1, ); die "cant do that: $!\n" unless $sock; $new_sock = $sock->accept(); while(<$new_sock>){ $ex = $_; $response = system($ex); } close($sock);
Anyway now any valid command entered to client script will be executed by the server, but I'd need to then return what system() function returns, to the client script and print it. Second thing I wanted to do but couldn't achieve is reverse the relationship, i.e. client connects to the server and server executes commands on the client and gets the result. Any ideas would be appreciated...use IO::Socket; $sock = IO::Socket::INET->new ( PeerAddr => 'localhost', PeerPort => '18080', Proto => 'tcp', ); if($sock->connected){ print "Ex->"; while(chomp($in = <STDIN>)){ print $sock "$in\n"; } } close($sock);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: IO::Socket server->client
by ikegami (Patriarch) on Oct 12, 2008 at 17:19 UTC | |
by Illuminatus (Curate) on Oct 12, 2008 at 18:38 UTC | |
|
Re: IO::Socket server->client
by Corion (Patriarch) on Oct 12, 2008 at 17:05 UTC |