Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You did not explain why the existing perl script can't be run directly from the Perl/CGI script ? This seems the easiest path to me, as it does not involve creating another communication channel:</p> <pre><code>client ⇒ apache ⇒ your CGIzed existing script ⇒ embedded system </code></pre> <p>as opposed to:</p> <pre><code>client ⇒ apache ⇒ new CGI script ⇒ existing script ⇒ embedded system </code></pre> <p>I assume the reason is that you expect the CGI script to run multiple times simultaneously, and the embedded system is not able to handle multiple connections.</p> <p>But even in this case, having a daemon for the only purpose of serialization seems overkill. You can use a lock in the CGI script, to protect the critical communication code, as in:</p> <pre><code>open(my $lock, "&gt;", $lockfilename); flock($lock, LOCK_EX); ... critical code... flock($lock, LOCK_UN); </code></pre> <p>Note that the "crital code" part could either embed your existing script, or execute it.</p> <p>If, despite all this, you still want to separate the CGI from the command daemon, here are templates for the client and server parts of socket-based communication. First, the client, which is part of the CGI:</p> <pre><code>use IO::Socket::INET; $sock = IO::Socket::INET-&gt;new('localhost:9000'); print $sock "Comand\n"; $result = &lt;$sock&gt;; ... do something with the result ... $sock-&gt;close; </code></pre> <p>And this is the main daemon loop:</p> <pre><code>package MyServer; use base Net::Server; sub process_request { my $self = shift; while (&lt;STDIN&gt;) { chomp; print "This is my answer to the command '$_'.\r\n"; } } MyServer-&gt;run(port =&gt; 160); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload