Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

How to use mod_perl as a socket server?

by opensourcer (Monk)
on May 09, 2007 at 11:13 UTC ( #614352=perlquestion: print w/ replies, xml ) Need Help??
opensourcer has asked for the wisdom of the Perl Monks concerning the following question:

hi,

Did any one tried to access/coonect directly to mod_perl using sockets. for example $peeraddress = http://somesite/modperl if any 1 did that, i need few suggestions on that.

what im trying to do
client code
#!/usr/bin/perl use strict; use IO::Socket; use URI; my $location = shift || "http://openbox:1011/MW"; my $url = new URI( $location ); my $host = $url->host || "openbox"; my $port = $url->port || 1011; my $path = $url->path || "/MW"; my $socket = new IO::Socket::INET (PeerAddr => $host, PeerPort => $port, Proto => 'tcp') or die "Cannot connect to the $host.\n"; $socket->autoflush (1); my $hash = { name => 'sourcer', pass => 'unknown', }; print $socket "POST $path HTTP/1.1","\n"; print $socket "Host: $host","\n\n"; print $socket "hello this is a test sentence"; #print while (<$socket>); $socket->close;
now the server code
use strict; use Data::Dumper; use IO::Socket; use Apache2::RequestRec (); use Apache2::Const -compile => ( 'OK', 'NOT_FOUND' ); use Apache2::compat; sub handler { $| = 1; my( $r ) = @_; #$r->content_type("text/html"); my $socket = IO::Socket::INET->new ( Peeraddr => "localhost +", BindPort => 1011, Proto => "tcp", type => SOCK_STREA +M, Listen => 256 ) or di +e "Couldn't connect : $@\n"; # wait for a connection my $new_sock = $socket->accept(); while (<$new_sock>) { print $_; } $socket->close;
i can connect to the server, but i send something to server nothing happens on server side, it does'nt log the client messages. note: Apache uses the same port that i mentioned in server code (peerport => 1011) thanks
Arun

Comment on How to use mod_perl as a socket server?
Select or Download Code
Re: How to use mod_perl as a socket server?
by Joost (Canon) on May 09, 2007 at 11:36 UTC

      I'm 99% sure opensourcer is doing something prosaic so this post is 99% sure to be irrelevant to him or her. I just wanted to respond to you to say that you can use mod_perl as a socket server. Override the Connection handler and you're free to leave http behind and go be something else entirely different. We've got an RPC sort of thing going instead. Apache+mod_perl is just a convenient server to hang our framework off of.

      ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊

Re: How to use mod_perl as a socket server?
by naikonta (Curate) on May 09, 2007 at 15:15 UTC
    Sure, I do that many times, directly from my command line.
    $ GET http://somesite/modperl
    It uses socket to connect to the site.

    Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://614352]
Approved by Joost
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (11)
As of 2014-12-22 12:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (116 votes), past polls