Crackers2 has asked for the wisdom of the Perl Monks concerning the following question:

Minimal code:

#!/usr/bin/perl use strict; use IO::Socket::INET; my $host = "www.google.com"; my $port = 80; my $fh = new IO::Socket::INET( PeerAddr => $host, PeerPort => $port, Proto => 'tcp', Timeout => 5, ) or die "$!"; print "sending\n"; print $fh "message\n"; print "send done\n";

This code runs fine on linux and windows when run as a script. However, if I make an executable out of it using pp (on windows), the script hangs after printing the "sending" message.

I admit that I haven't used pp before so perhaps I just need to add a parameter or something. Feel free to tell me to RTFM as long as you also include a link to that M, since google wasn't able to find it for me.

Perl version is ActivePerl Build 811 on windows 2000

Replies are listed 'Best First'.
Re: Can't write to socket using pp ?
by starbolin (Hermit) on May 12, 2005 at 06:46 UTC

    There is a saying:

    "Only Perl can parse Perl."
    I assume by pp you mean some kind of Perl Packager as opposed to the Perl byte code. Some things that could introducing dependancies:

    IO::Socket::INET->new returns a reference to a IO::Socket object. You should use defined() to check the return value or, better yet, enclose it in an eval.

    The use of a symbolic Filehandle involves a lot of perl magic which may not be portable.

    You should check if the socket is connecting.

    ($host eq $fh->connected()) or die "Can't connect to $host\n";
    Explicitly turn autoflush on.
    $fh->autoflush(1);
    Good Luck

    s//----->\t/;$~="JAPH";s//\r<$~~/;{s|~$~-|-~$~|||s |-$~~|$~~-|||s,<$~~,<~$~,,s,~$~>,$~~>,, $|=1,select$,,$,,$,,1e-1;print;redo}