D
doctorj
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
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