Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

CGI access to Perl Daemon

by PyroX (Pilgrim)
on Dec 17, 2002 at 20:12 UTC ( [id://220641]=perlquestion: print w/replies, xml ) Need Help??

PyroX has asked for the wisdom of the Perl Monks concerning the following question:

Good Day,

I have a question, and I admit I am have not yet done a lot of research on this, but ;)

Here is the situation, lets say I have a perl daemon that I don't know, maintains an socket connection to a server for some reason. Lets say this daemon keeps connection information and tracks all data from the socket in both directions (read/write) . Ok, that fine and dandy. Now lets note that this daemon will usually run all the time, with a connection that always exists.

Is it possible, with lets say, a CGI for example, to connect a particular daemon that is running, and get information from it. I do not want to launch a new daemon, but connect to an existing one. I do not have a real good example of why I want to do this.

Long story short, when they access the CGI via a webpage, the daemon is consulted and information is gathered from its stored information that it has gotten from its connection, some commands may be sent to the daemon, which change what it is doing, or gets new information.

Make sense? Is it possible / are there existing examples? Thanks for the input.

Replies are listed 'Best First'.
Re: CGI access to Perl Daemon
by Aristotle (Chancellor) on Dec 17, 2002 at 20:23 UTC
    Why shouldn't it? A CGI script is a program like any other, besides it method of invocation and a few special environment variables set at invocation. Anything you can do from a regular script, you can do from a CGI one. Just don't take too long to send any output or the connecting browser will time out the connection.

    Makeshifts last the longest.

Re: CGI access to Perl Daemon
by Mr. Muskrat (Canon) on Dec 17, 2002 at 20:23 UTC

    I have a question, and I admit I am have not yet done a lot of research on this, but ;)

    I have an answer, and I admit I have not done any research on this, but ;)
    Only if the daemon was written to allow you to do so.

Re: CGI access to Perl Daemon
by jdporter (Paladin) on Dec 17, 2002 at 20:40 UTC
Re: CGI access to Perl Daemon
by derby (Abbot) on Dec 17, 2002 at 21:05 UTC
    The actual connection is quite straight forward (check out the socket section of perlipc). The hard part is going to be designing/implementing the protocol your daemon will speak - that is once you have a connection, what meta-language (ala ftps get,set,dir,etc) are you going to use to control the transaction and convey status.

    -derby

Re: CGI access to Perl Daemon
by dws (Chancellor) on Dec 18, 2002 at 06:09 UTC
    Is it possible / are there existing examples?

    Yes, it's possible, and there examples, or at least significant pieces of examples that you can build from, in many Perl books. Consult the Perl Cookbook.

    There's nothing magic about opening up a socket from a CGI, writing to it, reading it from it, and sticking the result into HTML.

Re: CGI access to Perl Daemon
by PyroX (Pilgrim) on Dec 17, 2002 at 20:30 UTC
    Nice replies.

    I know I can connect via a CGI, my question is how to do:

    If I have:
    (daemon) < - > (socket) < - > (remote service)

    What will I need to do then for:
    (cgi) < - > (daemon)
      Consider using a web services protocol like XMLRPC::Lite - this makes it easy to pass Perl data structures ( at least the simpler ones ) from a CGI script to the daemon and back.

      The messages get passed as HTTP requests, and they are human readable, so debugging is made simpler.

Re: CGI access to Perl Daemon
by rcaputo (Chaplain) on Dec 18, 2002 at 02:57 UTC
Re: CGI access to Perl Daemon
by PyroX (Pilgrim) on Dec 17, 2002 at 21:45 UTC
    So to sum up here, the best way to do this is to write my daemon so it not only communicates via socket #1 to it's connection, it also listes and replies on socket #2 ( a port on the server ) to requests made by the cgi or basically any language then. Making the daemon multiple client compatable. This sounds good. I will do it this way unless anyone barks off a bad side.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-04-19 10:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found