Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Problems with IO::socket hanging on windows (works fine on Unix)

Reply
Thread Tools

Problems with IO::socket hanging on windows (works fine on Unix)

 
 
doctorj@blueyonder.co.uk
Guest
Posts: n/a
 
      06-02-2005
Hi there,

I am new to Perl, so probably making some schoolboy error. I am
developing a bit of code that opens a socket to an Apache server over a
port and sends a GET request to verify it is up and running. I am
using out-of-the-box Perl 5.6.1. The code works perfectly on
Unix(Solaris) but on Windows it just hangs.

The code gets the port number from a config file then uses this to open
a socket and send the GET request. The code is:

-----------------------

sub check_accept_http_request {

use sigtrap;
use IO::Socket;

$home = $ENV{'AP_HOME'};
$url = shift; print "URL is: $url\n";
$host = shift; print "Host is: $host\n";
$searchstring = "@_"; print "Search string is: $searchstring\n";

open FILE, "$home//install//ports.txt" or die "File ports.txt not
found";

while ($line = <FILE>) {

$i = index $line, $searchstring;
if ( $i == 0 ) {
if ($line =~ /(=)([ ]*)(\S+)/) {
$port = $3;
}
}
}

close FILE;

print "Port is: $port\n";

my $this_socket = new IO::Socket::INET (PeerAddr => $host, Timeout =>
"9", PeerPort => $port, Proto => "tcp", type => SOCK_STREAM);
print "Socket is: $this_socket\n";
if(!$this_socket){
$rcode = $!;
} else {
$get_request = ("GET $url HTTP/1.0\r\n" );
# $this_socket->print ($get_request);
# $this_socket->print("Accept: text/plain\n");
# $this_socket->print("Accept: text/html\n");
# $this_socket->print("UserAgent: LoogBrowser/1.0\n\n");
print $this_socket $get_request;
print $this_socket "Accept: text/plain\n";
print $this_socket "Accept: text/html\n";
print $this_socket "UserAgent: LoogBrowser/1.0\n\n";
$line=($this_socket->getline());
print "$line\n";
if($.==1){
($rcode)=($line=~/^\S+\s(\d+)\s(.*)$/);
}
close $this_socket;
}

print $rcode;
}

check_accept_http_request ("/index.html","localhost","HTTP Server");

---------------

When I run this little sub on Unix it all works a treat:

URL is: /index.html
Host is: localhost
Search string is: HTTP Server
Port is: 7777
Socket is: IO::Socket::INET=GLOB(0x1430bc)
HTTP/1.1 200 OK

But when I run it on windows, it hangs after it makes the socket:

URL is: /index.html
Host is: localhost
Search string is: HTTP Server
Port is: 7777
Socket is: IO::Socket::INET=GLOB(0x22e4a0)
<hangs indefinitely here>

Can anyone tell me what I am doing wrong? I'd be grateful for any help
you can provide.

Thanks,
Jon

 
Reply With Quote
 
 
 
 
Sherm Pendley
Guest
Posts: n/a
 
      06-02-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) writes:

> Hi there,
>
> I am new to Perl, so probably making some schoolboy error. I am
> developing a bit of code that opens a socket to an Apache server over a
> port and sends a GET request to verify it is up and running. I am
> using out-of-the-box Perl 5.6.1.


Any particular reason you're doing this by hand, instead of using the LWP
module? Not a criticism, just curious - you're putting a *lot* of effort
into re-inventing that wheel.

sherm--
 
Reply With Quote
 
 
 
 
doctorj@blueyonder.co.uk
Guest
Posts: n/a
 
      06-02-2005
Not particularly, Sherm. I hacked this out of something else I found.
Will have a look at the LWP module now.

Thanks,
Jon

 
Reply With Quote
 
doctorj@blueyonder.co.uk
Guest
Posts: n/a
 
      06-02-2005
Is LWP a default module? I will be running this thing on our clients'
installations and may not have the opportunity (or permission) to be
adding extra packages etc.

Thanks,
Jon

 
Reply With Quote
 
Sherm Pendley
Guest
Posts: n/a
 
      06-02-2005
(E-Mail Removed) writes:

> Is LWP a default module? I will be running this thing on our clients'
> installations and may not have the opportunity (or permission) to be
> adding extra packages etc.


No, it's a CPAN module.

Your clients should be easy to convince though - just compare what it
would cost them to pay you for about ten minutes to install LWP vs.
the time it would take you to re-invent it.

sherm--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
 
Reply With Quote
 
doctorj@blueyonder.co.uk
Guest
Posts: n/a
 
      06-02-2005
Hi Sherm,

I tried using LWP and it works a treat on both platforms. Strangely
the module seems to already be present by default in the Perl
installations I am using. This is possibly becuase they come as part
of an Oracle software installation and Oracle probably added them
already.

Thanks again for your advice! Much appreciated.

Jon

 
Reply With Quote
 
Sherm Pendley
Guest
Posts: n/a
 
      06-02-2005
(E-Mail Removed) writes:

> I tried using LWP and it works a treat on both platforms. Strangely
> the module seems to already be present by default in the Perl
> installations I am using.


Oh, right, I forgot! LWP's not a "core" module that distributed as
part of the Perl source, but it's included with ActiveState's Perl
for Windows.

sherm--

--
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org
 
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
Belkin Wireless Router Connection Problems/Hanging/Freezing Andrew Clancy Computer Support 7 12-19-2009 04:04 AM
Windows 2000 started hanging on startup . Computer Support 9 10-03-2005 09:29 PM
Slow Hanging Network Windows XP =?Utf-8?B?cmFuZHk=?= Wireless Networking 7 06-24-2005 01:44 AM
boutique and fine art royalty free images - free fine art image offer Andrew Mowat Digital Photography 0 09-14-2004 05:35 AM
Windows 98 se hanging on shutdown. SgtMinor Computer Support 6 07-21-2004 04:17 PM



Advertisments