Opening a listen socket on Windows 2000


T

T. Jansma

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";
}
 
Ad

Advertisements

F

Frank Zimper

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;
 

Top