1

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;
1
  • What specifically do you mean, "just hanging there"? What symptoms are you observing? When I run the above code (under 5.8 or 5.10), I get a fatal exception thrown by the new constructor: IO::Socket: Cannot configure a generic socket at bad-socket.pl line 8 Commented Jun 11, 2010 at 18:56

2 Answers 2

5

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?

Sign up to request clarification or add additional context in comments.

Comments

1

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.

1 Comment

btw, do the same mistake myself all the time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.