tags:

views:

62

answers:

2

when I run the following code, the execution is just hanging there, No response at all. does any of you can tell me what's wrong with the sample code?

use strict;
use warnings;
use IO::Select;
use IO::Socket;

my $s = new IO::Socket (
                          LocalPort => 8889,
                          Proto  => 'tcp',
                          Listen => 16,
                          Reuse  => 1
                      );

die "could not create socket $!\n" unless $s;
+5  A: 

If you provide arguments to the IO::Socket constructor it demands a Domain argument. Check out the full source here, specifically the configure subroutine which gets called from the constructor if you've provided arguments.

sub new {
  ...
  return scalar(%arg) ? $sock->configure(\%arg)
        : $sock;
}

sub configure {
  my($sock,$arg) = @_;
  my $domain = delete $arg->{Domain};

  croak 'IO::Socket: Cannot configure a generic socket' unless defined $domain;
  ....
}

Perhaps you're thinking of IO::Socket::INET?

MarquisDeMizzle
+1  A: 

what's wrong with the sample code?

IO::Socket is a generic super class for Perl sockets.

You need to replace the IO::Socket with IO::Socket::INET.

Dummy00001
btw, do the same mistake myself all the time.
Dummy00001