C
charlie.bursell
I have two Windows 2000 boxes in my home office. On each when I run
the code below, all I see on the host side is HEX 0000000c which
is the length only. Then the little program will hang until I kill it.
The weird thing is that this code works properly on Unix, Windows 2003
and another Windows 2000 box. I have tested it on all of these.
Can anyone at least point me in the right direction? This is running
me up a tree!
The code below is extracted from other perl utilities that I am trying
to use but when called will hang as does this little script.
Here is the code:
$port = 9988;
$thishost = localhost;
$AF_INET = 2;
$SOCK_STREAM = 1;
$proto = getprotobyname('tcp');
$sockaddr = 'S n a4 x8';
$thataddr = gethostbyname( $thishost );
# Form net address
$that = pack($sockaddr, $AF_INET, $port, $thataddr);
# Make the socket filehandle.
if (socket(S, $AF_INET, $SOCK_STREAM, $proto)) {
print "socket ok\n";
} else {
print "Unable to create socket to localhost on port $port\n";
die "Error was: $!\n";
}
# Set socket to be line buffered.
select(S); $| = 1; select stdout;
# Connect to the host.
if (connect(S, $that)) {
print "Connect ok\n";
} else {
print "Unable to contact host '$thishost' on port $port\n";
die "Error was: $!\n";
}
$txt = "Hello World!";
printf "Sending String: $txt\n";
# Write length encoding in network byte order, then string.
$len = length($txt);
print "Writing $len bytes to conn: '$txt'\n";
print S pack("N", $len); # 4-byte Network byte order
print S $txt;
close S;
the code below, all I see on the host side is HEX 0000000c which
is the length only. Then the little program will hang until I kill it.
The weird thing is that this code works properly on Unix, Windows 2003
and another Windows 2000 box. I have tested it on all of these.
Can anyone at least point me in the right direction? This is running
me up a tree!
The code below is extracted from other perl utilities that I am trying
to use but when called will hang as does this little script.
Here is the code:
$port = 9988;
$thishost = localhost;
$AF_INET = 2;
$SOCK_STREAM = 1;
$proto = getprotobyname('tcp');
$sockaddr = 'S n a4 x8';
$thataddr = gethostbyname( $thishost );
# Form net address
$that = pack($sockaddr, $AF_INET, $port, $thataddr);
# Make the socket filehandle.
if (socket(S, $AF_INET, $SOCK_STREAM, $proto)) {
print "socket ok\n";
} else {
print "Unable to create socket to localhost on port $port\n";
die "Error was: $!\n";
}
# Set socket to be line buffered.
select(S); $| = 1; select stdout;
# Connect to the host.
if (connect(S, $that)) {
print "Connect ok\n";
} else {
print "Unable to contact host '$thishost' on port $port\n";
die "Error was: $!\n";
}
$txt = "Hello World!";
printf "Sending String: $txt\n";
# Write length encoding in network byte order, then string.
$len = length($txt);
print "Writing $len bytes to conn: '$txt'\n";
print S pack("N", $len); # 4-byte Network byte order
print S $txt;
close S;