You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by mm...@tampabay.rr.com on 2004/02/06 16:34:11 UTC

[mp2] UDP communications in perl module running under mod_perl2

Apache/2.0.48 (Unix) mod_perl/1.99_12 Perl/v5.8.0

Should I have any  difficulty running a simple socket UDP Perl module
under the above configuration? Run directly from Perl, I'm able to 
send/recv from an external server. However, run from the apache server, 
the recv fails. (I've tried the Perl Socket module and the recv doesn't 
complete. If I use IO:Socket, the recv returns with a 'connection 
refused'.)

I see the references to APR socket routines in mp2. Do I need to use those?


Thanks,
Michael Maciag


-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [mp2] UDP communications in perl module running under mod_perl2

Posted by Michael Maciag <mm...@tampabay.rr.com>.
Fortified with the responses from Philippe and Stas, I went back and, after
re-examining the entire configuration, found a typo that was causing my
error.

Now, no problem at all working with the third-party server over UDP from
mod_perl2 using IO::Socket::INET.

Yours, chagrined,
Michael Maciag

-----Original Message-----
From: Philippe M. Chiasson [mailto:gozer@cpan.org]
Sent: Wednesday, February 11, 2004 4:16 PM
To: Stas Bekman
Cc: Michael Maciag; modperl@perl.apache.org
Subject: Re: [mp2] UDP communications in perl module running under
mod_perl2


On Wed, 2004-02-11 at 10:53 -0800, Stas Bekman wrote:
> Michael Maciag wrote:
> >>Which Unix? I've heard about the troubles with sockets on AIX (w/
mod_perl
> >
> > 1)
> >
> > Solaris 8.
> >
> >
> >>Have you read:
> >
> > Yes. However, unless I'm confused, that is a bit different in that it is
an
> > example of using APR to work with the socket established by Apache to
> > communicate with the client. I need to establish my own UDP conversation
> > with a "third-party" service from where I'll retrieve data which I'll
use to
> > compose my response to the client. If I can use APR to do that, great,
but I
> > couldn't find docs/samples/tests that create/open/close APR sockets.
>
> Ah, then yes, you should be able to use Perl sockets. I doubt that the
problem
> has to do anything with mod_perl, though. YOu said that recv fails, but
you
> dind't specify what was the error message.
>
> Also I remember Philippe was working on mod_udp or something like that, so
he
> certainly will know if there are any special Apache issues to deal with.
Philippe?

If you are trying to send an UDP query over to a server and read a
response from it in Perl, there is no problem, really, i.e.:

use strict;
use IO::Socket::INET;

sub handler {
	my $r = shift;


	my $socket = new IO::Socket::INET (
    		PeerAddr => 'localhost:echo',
    		Proto    => 'udp',
    		Type     => SOCK_DGRAM,
    		) || die $!;

		$socket->send($r->path_info) || die $!;

		my $response;
		$socket->recv($response, length($r->path_info)) || die $!;

		print ($r->path_info eq $response) ? "OK" : "NOK";
}


Just works fine! In a case like this one, trying to use APR for UDP is
overkill. Use Perl.

Gozer out.

> __________________________________________________________________
> Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
> http://stason.org/     mod_perl Guide ---> http://perl.apache.org
> mailto:stas@stason.org http://use.perl.org http://apacheweek.com
> http://modperlbook.org http://apache.org   http://ticketmaster.com
--
Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID :
88C3A5A5
http://gozer.ectoplasm.org/     F9BF E0C2 480E 7680 1AE5 3631 CB32 A107
88C3A5A5



-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [mp2] UDP communications in perl module running under mod_perl2

Posted by "Philippe M. Chiasson" <go...@cpan.org>.
On Wed, 2004-02-11 at 10:53 -0800, Stas Bekman wrote:
> Michael Maciag wrote:
> >>Which Unix? I've heard about the troubles with sockets on AIX (w/ mod_perl
> > 
> > 1)
> > 
> > Solaris 8.
> > 
> > 
> >>Have you read:
> > 
> > Yes. However, unless I'm confused, that is a bit different in that it is an
> > example of using APR to work with the socket established by Apache to
> > communicate with the client. I need to establish my own UDP conversation
> > with a "third-party" service from where I'll retrieve data which I'll use to
> > compose my response to the client. If I can use APR to do that, great, but I
> > couldn't find docs/samples/tests that create/open/close APR sockets.
> 
> Ah, then yes, you should be able to use Perl sockets. I doubt that the problem 
> has to do anything with mod_perl, though. YOu said that recv fails, but you 
> dind't specify what was the error message.
> 
> Also I remember Philippe was working on mod_udp or something like that, so he 
> certainly will know if there are any special Apache issues to deal with. Philippe?

If you are trying to send an UDP query over to a server and read a
response from it in Perl, there is no problem, really, i.e.:

use strict;
use IO::Socket::INET;

sub handler {
	my $r = shift;
	

	my $socket = new IO::Socket::INET ( 
    		PeerAddr => 'localhost:echo',
    		Proto    => 'udp',
    		Type     => SOCK_DGRAM,
    		) || die $!;

		$socket->send($r->path_info) || die $!;
		
		my $response;
		$socket->recv($response, length($r->path_info)) || die $!;

		print ($r->path_info eq $response) ? "OK" : "NOK";
}


Just works fine! In a case like this one, trying to use APR for UDP is
overkill. Use Perl.

Gozer out.

> __________________________________________________________________
> Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
> http://stason.org/     mod_perl Guide ---> http://perl.apache.org
> mailto:stas@stason.org http://use.perl.org http://apacheweek.com
> http://modperlbook.org http://apache.org   http://ticketmaster.com
-- 
Philippe M. Chiasson m/gozer\@(apache|cpan|ectoplasm)\.org/ GPG KeyID : 88C3A5A5
http://gozer.ectoplasm.org/     F9BF E0C2 480E 7680 1AE5 3631 CB32 A107 88C3A5A5

Re: [mp2] UDP communications in perl module running under mod_perl2

Posted by Stas Bekman <st...@stason.org>.
Michael Maciag wrote:
>>Which Unix? I've heard about the troubles with sockets on AIX (w/ mod_perl
> 
> 1)
> 
> Solaris 8.
> 
> 
>>Have you read:
> 
> Yes. However, unless I'm confused, that is a bit different in that it is an
> example of using APR to work with the socket established by Apache to
> communicate with the client. I need to establish my own UDP conversation
> with a "third-party" service from where I'll retrieve data which I'll use to
> compose my response to the client. If I can use APR to do that, great, but I
> couldn't find docs/samples/tests that create/open/close APR sockets.

Ah, then yes, you should be able to use Perl sockets. I doubt that the problem 
has to do anything with mod_perl, though. YOu said that recv fails, but you 
dind't specify what was the error message.

Also I remember Philippe was working on mod_udp or something like that, so he 
certainly will know if there are any special Apache issues to deal with. Philippe?

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


RE: [mp2] UDP communications in perl module running under mod_perl2

Posted by Michael Maciag <mm...@tampabay.rr.com>.
> Which Unix? I've heard about the troubles with sockets on AIX (w/ mod_perl
1)

Solaris 8.

> Have you read:
Yes. However, unless I'm confused, that is a bit different in that it is an
example of using APR to work with the socket established by Apache to
communicate with the client. I need to establish my own UDP conversation
with a "third-party" service from where I'll retrieve data which I'll use to
compose my response to the client. If I can use APR to do that, great, but I
couldn't find docs/samples/tests that create/open/close APR sockets.

Thanks,
Michael Maciag

-----Original Message-----
From: Stas Bekman [mailto:stas@stason.org]
Sent: Wednesday, February 11, 2004 4:41 AM
To: mmaciag@tampabay.rr.com
Cc: modperl@perl.apache.org
Subject: Re: [mp2] UDP communications in perl module running under
mod_perl2


mmaciag@tampabay.rr.com wrote:
> Apache/2.0.48 (Unix) mod_perl/1.99_12 Perl/v5.8.0

Which Unix? I've heard about the troubles with sockets on AIX (w/ mod_perl
1)

> Should I have any  difficulty running a simple socket UDP Perl module
> under the above configuration? Run directly from Perl, I'm able to
> send/recv from an external server. However, run from the apache server,
> the recv fails. (I've tried the Perl Socket module and the recv doesn't
> complete. If I use IO:Socket, the recv returns with a 'connection
> refused'.)
>
> I see the references to APR socket routines in mp2. Do I need to use
those?

Yup. Have you read:
http://perl.apache.org/docs/2.0/user/handlers/protocols.html
In particular:
http://perl.apache.org/docs/2.0/user/handlers/protocols.html#Socket_based_Pr
otocol_Module

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

--
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html




-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [mp2] UDP communications in perl module running under mod_perl2

Posted by Stas Bekman <st...@stason.org>.
mmaciag@tampabay.rr.com wrote:
> Apache/2.0.48 (Unix) mod_perl/1.99_12 Perl/v5.8.0

Which Unix? I've heard about the troubles with sockets on AIX (w/ mod_perl 1)

> Should I have any  difficulty running a simple socket UDP Perl module
> under the above configuration? Run directly from Perl, I'm able to 
> send/recv from an external server. However, run from the apache server, 
> the recv fails. (I've tried the Perl Socket module and the recv doesn't 
> complete. If I use IO:Socket, the recv returns with a 'connection 
> refused'.)
> 
> I see the references to APR socket routines in mp2. Do I need to use those?

Yup. Have you read:
http://perl.apache.org/docs/2.0/user/handlers/protocols.html
In particular:
http://perl.apache.org/docs/2.0/user/handlers/protocols.html#Socket_based_Protocol_Module

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html