hi monks,

Recently I started to mess around with socket programming in perl, and I've little stumped on this piece of code, which is supposed to be simple script to communicate through the socket s:
Server
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);


Client
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);
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...

Again thanks for any help

In reply to IO::Socket server->client by clone4

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.