Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Weird socket happenings

Reply
Thread Tools

Weird socket happenings

 
 
charlie.bursell@quovadx.com
Guest
Posts: n/a
 
      12-27-2005
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;

 
Reply With Quote
 
 
 
 
Henry Law
Guest
Posts: n/a
 
      12-27-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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!


Can't help with the Perl socket stuff as I'm not familiar with it. But
I strongly suspect that's not where the problem lies. Some suggestions
(which, as you're obviously an adept, you've probably thought of).

* First, have you tried tracing the traffic on the network? tcpdump is
available for Windows and may be installed already on your UNIX
machine. Would be worth seeing - confirming - that the packet is
correctly formed.

* You say your "sending" program hangs until you kill it. Where does
it hang? Does it run under debug? (perl -d, that is). If not,
have you tried bunging print statements in between every line to
see which one is executed before the hang?

* It might be worth distilling the "sender" even more by hard-coding
your packet (read it out of a file, created with a hex editor,
maybe) and the IP address, just to eliminate further causes of
difference. (Can you hear the sound of straws being clutched at?)

* Fix levels on the "good" and the "renegade" W2K machines? If they're
different then could you up-level one of renegades to the same
level as the good one? Same goes for levels of Perl. Could be
worth up-levelling to the latest build of ActiveState (assuming that's
what you're running).

* Could there be some difference in user permissions between the good
machine and the renegades? Run as "administrator" if you haven't
already.

--

Henry Law <>< Manchester, England
 
Reply With Quote
 
 
 
 
Mark Clements
Guest
Posts: n/a
 
      12-27-2005
(E-Mail Removed) wrote:
> 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);



<snip>

A few thoughts:

you need to run with

use strict;
use warnings;

This will enable perl itself to catch a whole slew of potential errors;
this will save you much grief.

There is no need to define $AF_INET and $SOCK_STREAM yourself: there are
constants defined in Socket for this purpose. Check out

perldoc Socket

What do you expect to be listening on tcp port 9988? If there isn't
anything listening on the host to which you are connecting (ie
localhost), your client script isn't going to connect. What is the exact
output your script produces?

> $txt = "Hello World!";

My initial feeling was that you had misspelt this, but a quick google
appears to show that the jury is out. This has no bearing on your
issues, though

Mark
 
Reply With Quote
 
charlie.bursell@quovadx.com
Guest
Posts: n/a
 
      12-27-2005
Thanks for the reply. I have tried all of the above, traces, etc..
Both W2K machines at SP 4.
Tried the debug, it works up to where the script hangs.

I have put *MANY* print statements. The script hangs at the "print S"
statement.

The point here is, though poorly written, this little script works
everywhere but on my two machines.

 
Reply With Quote
 
Big and Blue
Guest
Posts: n/a
 
      12-28-2005
(E-Mail Removed) wrote:
>
> $port = 9988;
> $thishost = localhost;
> $AF_INET = 2;


No - it isn't. Well, it might be, but it is actually whatever AF_INET
is defined to be on your system. At leats one system (I forget which) has
AF_INT (or PF_INET) defined as somethign other then 2.

> $SOCK_STREAM = 1;


Similarly for that.

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


Why not just:

my $s = IO::Socket::INET->new(Port => $port, ....etc.);

and re-use the code which is already there?



--
Just because I've written it doesn't mean that
either you or I have to believe it.
 
Reply With Quote
 
axel@white-eagle.invalid.uk
Guest
Posts: n/a
 
      12-28-2005
(E-Mail Removed) <(E-Mail Removed)> wrote:
> Thanks for the reply. I have tried all of the above, traces, etc..


What reply? PLease quote some context.

Axel

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange Happenings dwacon Computer Support 1 05-03-2005 03:20 AM
Strange happenings... cannot delete when program WAS using it but not IS Atreju Computer Support 4 11-26-2004 04:11 PM
Strange Happenings d w a c o n Computer Support 6 02-22-2004 11:12 PM
Strange Explorer happenings Cuzman Computer Support 2 08-01-2003 03:02 AM
Strange happenings in explorer Cuzman Computer Support 1 07-19-2003 10:21 PM



Advertisments