Opening a listen socket on Windows 2000

Discussion in 'Perl Misc' started by T. Jansma, Nov 18, 2004.

  1. T. Jansma

    T. Jansma Guest

    Hi everyone,

    I've got a very weird problem. I'm writing a perl script that runs as
    a service on windows 2000/xp/2003. It starts a seperate listening
    thread to listen for connections and do the processing that's needed.
    The multithreading part and running as a service part all work fine on
    all platforms.
    However, the opening of a listen socket only works on Windows XP. I
    can't figure out why though, is the $! also remains empty. On Windows
    2000 (server) and Windows 2003 (server) it just says that the
    $listenSocket is undefined, $! remains empty. Can anyone see what's
    happening in the code below?
    I've tries a multitude of options in the IO::Socket::INET->new()
    method, but nothing worked sofar. The options that are in there now
    are only part of the last attempt :)

    (It's the code that comprises the listener thread):

    ---
    sub listenerThread() {
    my $listenSocket;
    my $processSocket;
    my $dataRcvd;
    my $peerIPAddr;
    my $peerHostname;
    my $peerDomainname;
    my @hosts;

    print DEBUG "This is the listener waking up!\n";

    $listenSocket = IO::Socket::INET -> new( Listen => 5,
    MultiHomed => 1,
    LocalPort => 6666,
    LocalHost => "172.24.2.6",
    Proto => "tcp",
    Reuse => 1,
    Blocking => 0
    );
    print DEBUG "Listening socket could not be created. Reason: $!\n" if
    ( ! $listenSocket );

    while ( $listenerControl eq "run" ) {
    if ( $processSocket = $listenSocket->accept() ) {
    print DEBUG "Processing socket could not be created. Reason:
    $!\n" if ( ! $processSocket );
    print DEBUG "Received data\n";

    open( TEST, ">>c:\\temp\\test.svc" );
    print TEST "Socket opened.\n";

    $peerIPAddr = $processSocket->peerhost();
    print TEST "$peerIPAddr\n";

    while ( defined( $dataRcvd = <$processSocket> ) ) {
    #->get_line();
    chomp( $dataRcvd );
    print TEST "$dataRcvd\n";

    if ( $dataRcvd =~ /Hostname:(.+)/ ) {
    $peerHostname = $1;
    print TEST "Matched hostname: $peerHostname\n";
    }

    if ( $dataRcvd =~ /Domainname:(.+)/ ) {
    $peerDomainname = $1;
    print TEST "Matched domainname: $peerDomainname\n";
    }
    }

    close( $processSocket );
    print TEST "Socket closed\n";

    #open( TEST, ">>c:\\temp\\test.svc" );
    print TEST "$peerIPAddr\t$peerHostname.$peerDomainname\t$peerHostname\n";
    close( TEST );

    if ( defined( $peerHostname ) && defined( $peerDomainname ) ) {
    updateHostsFile( $peerIPAddr, $peerHostname, $peerDomainname
    );
    }

    undef( $peerIPAddr );
    undef( $peerHostname );
    undef( $peerDomainname );
    }
    }

    print DEBUG "This is the listener dying!\n";
    }
    ---

    Thanks in advance!
    Tim.
     
    T. Jansma, Nov 18, 2004
    #1
    1. Advertising

  2. T. Jansma

    Frank Zimper Guest

    Hm, this worked for me, at least on Perl 5.6:

    # Create Socket
    my $sock = new IO::Socket::INET (
    LocalHost => 'localhost',
    LocalPort => '6666',
    Proto => 'tcp',
    Listen => 1,
    Reuse => 1,
    );
    die "Could not create socket: $!\n" unless $sock;


    >
    > $listenSocket = IO::Socket::INET -> new( Listen => 5,
    > MultiHomed => 1,
    > LocalPort => 6666,
    > LocalHost => "172.24.2.6",
    > Proto => "tcp",
    > Reuse => 1,
    > Blocking => 0
    > );
    > print DEBUG "Listening socket could not be created. Reason: $!\n" if
    > ( ! $listenSocket );
     
    Frank Zimper, Nov 20, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    2
    Views:
    960
    dave wanta
    Jul 11, 2003
  2. Ryan Stewart
    Replies:
    1
    Views:
    856
    Tor Iver Wilhelmsen
    Jan 17, 2004
  3. cyril
    Replies:
    3
    Views:
    8,441
    Missaka Wijekoon
    Jun 25, 2004
  4. Donny
    Replies:
    13
    Views:
    703
    Donny
    Aug 5, 2004
  5. Replies:
    7
    Views:
    309
    CBFalconer
    Jun 19, 2007
Loading...

Share This Page