use IO::Socket;

my $url = 'localhost';
my $port = 6464;

my $error = 1;
my $sock ;

while ($error) {
   my $sock = new IO::Socket::INET (
	LocalHost => $url,
	LocalPort => $port,
	Proto => 'tcp',
	Listen => 1,
	Reuse => 1 );

    $error = 0 ;
    $error =1 unless $sock;

 print "Listener Port Established \n";

 $error =1 ;
 while ($error) {
    my $new_sock = $sock->accept();
    $error =0 ;
    $error =1 unless $new_sock;

 print "Connection Established \n";

 while (<$new_sock>) {
     print $_;


What I get is:
Listener Port Established
Can't call method "accept" on an undefined value at /usr/mbin/testserv.pl line 27.

Any ideas? RH 8 linux (upgradeing OS is not an option)

Apparantly, in my code, the "my $sock..." needed to
have the "my" removed. Since it was in a block, the
"my" was causing the variable to become localized,
and once outside the block, it didn't exist.

Once I remove the "my" and made the variable a
global one, it worked fine.


This question has already been answered. Start a new discussion instead.