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.
Re: CGI access to Perl Daemon
by Aristotle (Chancellor) on Dec 17, 2002 at 20:23 UTC
|
| [reply] |
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.
| [reply] |
Re: CGI access to Perl Daemon
by jdporter (Paladin) on Dec 17, 2002 at 20:40 UTC
|
| [reply] |
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 | [reply] |
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.
| [reply] |
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)
| [reply] |
|
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.
| [reply] |
Re: CGI access to Perl Daemon
by rcaputo (Chaplain) on Dec 18, 2002 at 02:57 UTC
|
| [reply] |
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. | [reply] |
|
|