I'm on Linux 2.4.20, with Apache 1.3.27, mod_perl 1.27, perl 5.6.1, connecting locally to a postgres db. My previous guess had to be wrong because you said the code
worked if you replaced

$socket = new IO::Socket::INET(
PeerAddr => $host,
PeerPort => $port,
Proto => 'tcp')
or die "Cannot connect to $port at $host";


with

$socket = new IO::Socket::INET(
PeerAddr => 'gaia',
PeerPort => 4444,
Proto => 'tcp')
or die "Cannot connect to $port at $host";


Have you tried just extracting the code to a small test program, defining the environment variables on the command line and running it through the perl debugger?

dhfg wrote:

Hi David,

The $socket, $host, and $port are all defined locally, ie. my $host, $port,
$socket (I missed them out while writing the email). What platform are you
trying it out. I have the socket client running within the Apache server on
the Solaris and making the connection to the Socket server running on a
Window XP PC. Wonder if this may cause the problem.

Cheers,
Dean



-----Original Message-----
From: David Dick [mailto:[EMAIL PROTECTED]]
Sent: Thursday, 6 February 2003 7:17 PM
To: dhfg
Cc: [EMAIL PROTECTED]
Subject: Re: Environment variable in Apache/mod_perl/IO::Socket


G'day Dean,
I just tried it and it seemed to work fine. (i just tried connecting to
my db instead and printed the value of $socket to STDERR). The only
question I have is where are $socket, $host and $port defined? They do
not seem to be local to the routine, so is it possible that is where the
confusion is happening?
Uru
-Dave

dhfg wrote:


Hi,

In my web application, I am using Apache server with mod_perl. In one of

my

Perl modules, I am creating a client socket using IO::Socket::INET which is
accepting the hotsname and port values from the environment variables set

in

the Apache config file http.conf. For some reason, this didn't work
eventhough I have verified that the values were set and retrieved

correctly.

Below is the extract of my codes:

In the config file http.conf:

PerlSetEnv AGENT_SOCKET_HOST 'gaia'
PerlSetEnv AGENT_SOCKET_PORT 4444

In my AgentSocket.pm:

use strict;
use IO::Socket::INET;
sub new
{
$host = $ENV{AGENT_SOCKET_HOST}; # I have checked these values are same
as
$port = $ENV{AGENT_SOCKET_PORT}; # those set in the http.conf

$socket = new IO::Socket::INET(
PeerAddr => $host,
PeerPort => $port,
Proto => 'tcp')
or die "Cannot connect to $port at $host";
:
return $socket;

}

The above socket did not get connect to the server but didn't die either.
But if I assigned
$host='gaia', $port='4444' within the AgentSocket.pm then it worked fine.

I have been tearing my hair out for days now and can't find the answer.
Perhaps you could help. Thanks in advance.

Regards,
Dean









Reply via email to