In addition to communicating via a file (both CGI and client2 are on the same machine is what I understood, also that client2 is running as a daemon waiting for data), you can also have them communicating via a socket, its port must be blocked by firewall so that client2 is not accessed externally.

Every time client1 calls the CGI script, a new instance of the script is created. Which means that a new socket to client2 must be created every time. So, this solution too has its overheads.

Assuming you do not have too many requests, then writing data to a file may not be a bad solution. It could be faster if you created a ramdisk and write/read all your data files there.

If there are multiple parallel requests from client1 to server then you will have a problem with unique datafiles/requests to client2 and also keeping track of whose request was first so that it is served first. Both problems easily sorted but with added overheads.

The most controversial solution would be for the server to system() client2 with all of its data either as a commandline param or as a file.

If you are flexible and client2 is not already a standalone program, why not write client2 as a Perl module and have your CGI script do something like:

# in CGI script use Client2; my $client2 = new Client2($params); my $output = $client2->process($data); print $output;

That's the route I would take.

bw, bliako


In reply to Re: CGI send data to client by bliako
in thread CGI send data to client by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.