Hi,

another more perlish way and perhaps of academic interest could be this using the IO::socket-modul

recip is listening on homer ...

tos@homer ~/tos/tmp # cat recip #!/usr/bin/perl use strict; use warnings; use IO::Socket; my $socket=new IO::Socket::INET (LocalPort => 1960, Proto => 'tcp', Listen => 5, Reuse => 1, ); die "could'nt create socket: $!" unless $socket; while (my $new_socket = $socket->accept()) { while (defined (my $buf = <$new_socket>)) { print $buf; $buf =~ /^ls/ && do { system ("ls") }; } } close ($socket);
... while sndr ...
tos@VRANZ /cygdrive/t/tos/tmp # cat sndr #!/usr/bin/perl use strict; use warnings; use IO::Socket; my $socket=new IO::Socket::INET (PeerAddr => 'homer', PeerPort => 1960, Proto => 'tcp' ); die "couldn't create socket: $!" unless $socket; foreach (1..3) { print $socket "message $_\n"; $socket->flush(); } print $socket "ls\n"; $socket->flush(); close ($socket);
... sends some messages from VRANZ ...
tos@VRANZ /cygdrive/t/tos/tmp # perl sndr tos@VRANZ /cygdrive/t/tos/tmp #
recip receives the messages, dumps them and proceeds the "ls"-cmd
tos@homer ~/tos/tmp # perl recip message 1 message 2 message 3 ls recip sndr sndr~ x
Be aware that this code is merely as secure as ftp and telnet are. For secure connections i can imagine that there is something to find at CPAN. Otherwise use the former recommended ssh-utilities.

greetings, tos


In reply to Re: Sockets, And Running Commands. by tos
in thread Sockets, And Running Commands. by hiddenlinux

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.