[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: IDL on the NET(ION) Anybody used it?



Peter Brooker <ra5589@email.sps.mot.com> wrote:
>Does anybody have experience with this? I want to create a fairly simple
>modeling program that could be accessed through the net. The program
>will display a multiline graph that will change as the user changes
>inputs.

I haven't used it, but, I have written a sort-of el cheapo replacement. My version
is primitive and insecure but it works, a bit. To use it publicly, you'd
definitely have to fix the security problems. But in case its useful, here it is:

-W.

--- the perl script ---
#!/users/icd/wmc/bin/perl

# This script runs as a server. It listens to port $PORT for IDL
# commands encoded in URLs and responds to them, drawing pictures
# to the Z-buffer and returning the image as image/gif.
# If the plot fails you get an unhelpful error message (but hey, you do at least get one).

# Security:
#   The script runs as me. It will reject commands with "spawn" in.
#   This should be beefed up a bit
# State:
#   The idl process retains state - you can use variables defined in one call for the next.
#   But... you may inherit things you don't want (!p.multi, for example)
# Interface:
#   See http://www.nbs.ac.uk/public/icd/wmc/perl/idl-server.html
# Bugs:
#   Needs a reset mechanism for state
# Fixes:
#   2000/02/02 - prefix commands with "retall" to catch some errors

use IO::Socket;
use Time::HiRes qw(sleep);

$|=1;

$server = IO::Socket::INET->new(LocalPort => 1234, Type => SOCK_STREAM, Reuse => 1, Listen => 10) or
  die "Can't open port";

open IDL, "| idl" or die "Failed to open IDL";
IDL->autoflush;
print IDL "set_plot,'Z'\ndevice,set_res=600*[1,1.25]\npolyfill,[0,1,1,0,0],[0,0,1,1,0],col=!p.background,/norm\nxyouts,0.5,0.5,/norm,'sorry your plot failed'\n";

$Nclient=0;
while ($client = $server->accept()) {
  $data=<$client>;
  ($requested)=($data=~/\?([^ ]*?) /);
  $requested =~ s/\+/ /g;
  $requested =~ s/%(\w\w)/sprintf("%c", hex($1))/ge; 
  #print "<req: $requested>\n";
  ($cmd)=($requested=~/idl-cmd\=(.*)/ms);
  $cmd =~ s/\\n/\n/g;
  #print "<cmd: $cmd>\n";

  if ($cmd =~ /spawn/) {

        print $client "HTTP/1.0 404\nContent-type: text/html\n\nBad command."

  } elsif ($cmd) {

    `echo 1 > idl-server-lock`;
    $idl_cmd="retall\n$cmd \ngettwogifs,/nosm,out='/tmp/wmc/wmc-idl-junk'\nspawn,'rm idl-server-lock'\n";
    print "Will send to IDL:\n".$idl_cmd;
    print IDL $idl_cmd;
    while (-r "idl-server-lock") { 
      sleep(0.5)
    };
    open IDLIN,"/tmp/wmc/wmc-idl-junk.gif";
    $image=join("",<IDLIN>);
    print $client "HTTP/1.0 200 Document follows\nContent-type: image/gif\n\n".$image;
    close IDLIN;

  } else {

        print $client "HTTP/1.0 404\nContent-type: text/html\n\nFailure, sorry. Try again?"

  };
  close $client;
  $Nclient++;
};

--- End ---
 
William M Connolley | wmc@bas.ac.uk | http://www.nbs.ac.uk/public/icd/wmc/
Climate Modeller, British Antarctic Survey | Disclaimer: I speak for myself