title: Remote command execution using perl client-server (socket)
body: <p>My client.pl</p>
  
  <pre><code>#!/usr/bin/perl
  use IO::Socket::INET;
  use strict;
  
  my $name = '172.20.10.189'; #Server IP
  my $port = '7890';
  
  my $socket = IO::Socket::INET-&gt;new('PeerAddr' =&gt; $name,
                                     'PeerPort' =&gt; $port,
                                  'Proto' =&gt; 'tcp') or die "Can't create socket ($!)\n";
  
  print "Client sending\n";
  while (1) {
      my $msg = &lt;STDIN&gt;;
      print $socket $msg;
      print scalar &lt;$socket&gt;;
  }
  close $socket
      or die "Can't close socket ($!)\n";
  </code></pre>
  
  <p>My server.pl</p>
  
  <pre><code>#!/usr/bin/perl
  use IO::Socket::INET;
  use strict;
  
  my $port = "7890";
  
  my $socket = IO::Socket::INET-&gt;new('LocalPort' =&gt; $port,
                                     'Proto' =&gt; 'tcp',
                                     'Listen' =&gt; SOMAXCONN)
      or die "Can't create socket ($!)\n";
  
  
  while (my $client = $socket-&gt;accept) {
      my $name = gethostbyaddr($client-&gt;peeraddr, AF_INET);
      my $port = $client-&gt;peerport;
      while (&lt;$client&gt;) {
          print "[$name $port] $_";
          my @out = `$_`;
          print @out;
          print $client "$.: @out";
      }
      close $client
          or die "Can't close ($!)\n";
  }
  
  die "Can't accept socket ($!)\n";
  </code></pre>
  
  <p>My client is sending a command (ls -lrt /) to the server and Server is supposed to run that command and send output to the client back.</p>
  
  <p>Problem:-</p>
  
  <p>The command is executed successfully on the server but it sends only first line to the client. If I press any key from client again the next line of output is sent to the client.</p>
  
  <p>Or tell me how to send multiple line output to back to client.</p>
  
  <p>Any help would be appreciated.</p>
  
  <p>Thanks
  Abhishek </p>