Simple Socket Programming
(based on www.perlfect.com/articles/sockets.shtml)
First, the receiver:
------------------------------------------------------------------
#!/usr/bin/perl
use strict;
my $input;
use IO::Socket;
my $sock=new IO::Socket::INET(
LocalHost => '192.168.1.29',
LocalPort => '7070',
Proto => 'tcp',
Listen => 1,
Reuse =>1);
die "Could not creat socket $!\n" unless $sock;
my $new_sock=$sock->accept();
while( $input=<$new_sock>)
{
print $input;
}
close($sock);
----------------------
Next, the sender :
-----------------------------------------------
#!/usr/bin/perl
use strict;
my $output;
use IO::Socket;
my $sock=new IO::Socket::INET(
PeerAddr => '192.168.1.29',
PeerPort => '7070',
Proto => 'tcp');
die "Could not creat socket $!\n" unless $sock;
while(1)
{
$output=<STDIN>;
print $sock $output;
}
close($sock);