H
Harshavardhan
Hi,
I am trying to create two sender and listener sockets using perl.
***************
Listener.pl
***************
#! /usr/bin/perl
use IO::Socket;
$sock = new IO::Socket::INET ( LocalHost => 'localhost',
Local Port => 1200,
Proto = 'tcp',
Listen = 5,
Reuse = 1);
die "Socket could not be created. Reason: $!" unless $sock;
while ( $new_sock = $sock->accept() ) {
while (defined ($buf = <$sock>)) {
print $buf;
}
}
close ($sock)
***********************
Sender.pl
***********************
#! /usr/bin/perl
use IO::Socket;
$sock = new IO::Socket::INET ( PeerAddr => 'localhost',
PeerPort => 1200,
Proto = 'tcp',
);
die "Socket could not be created. Reason: $!" unless $sock;
foreach (1 .. 10) {
print $sock "Msg $_: How are you? \n";
}
close ($sock)
***********************
When run the Listener, it waits for new connections, but when I run the
sender.pl, it just finishes without any output at the listener. I get no
error messages.
Any ideas on whats happening?
Thanks
harsha
when I run hostname on my computer, it returns localhost.localdomain. I am
running both the sender and the listener on my computer. I am using Perl
5.8.0
I am trying to create two sender and listener sockets using perl.
***************
Listener.pl
***************
#! /usr/bin/perl
use IO::Socket;
$sock = new IO::Socket::INET ( LocalHost => 'localhost',
Local Port => 1200,
Proto = 'tcp',
Listen = 5,
Reuse = 1);
die "Socket could not be created. Reason: $!" unless $sock;
while ( $new_sock = $sock->accept() ) {
while (defined ($buf = <$sock>)) {
print $buf;
}
}
close ($sock)
***********************
Sender.pl
***********************
#! /usr/bin/perl
use IO::Socket;
$sock = new IO::Socket::INET ( PeerAddr => 'localhost',
PeerPort => 1200,
Proto = 'tcp',
);
die "Socket could not be created. Reason: $!" unless $sock;
foreach (1 .. 10) {
print $sock "Msg $_: How are you? \n";
}
close ($sock)
***********************
When run the Listener, it waits for new connections, but when I run the
sender.pl, it just finishes without any output at the listener. I get no
error messages.
Any ideas on whats happening?
Thanks
harsha
when I run hostname on my computer, it returns localhost.localdomain. I am
running both the sender and the listener on my computer. I am using Perl
5.8.0