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

Re: [MacPerl] server push



> mean nothing to those of us developing with PERL for portabillity. Unless
> some beknighted soul has gotten Frontier and Mac Scripting to work on a
> Windows NT machine there is no easy solution here.
>
> If ANYONE has ANY working version of a server push using MacPERL running I
> will pay hansomely for the code. I need it to test our scripts on our Mac
> server before moving them off to the NT server.


I have posted about this before. Yes, you can do server push with MacPerl,
if (1) you don't care about timing tricks and you just want the animation
to come to the browser as fast as the modem will download it, and (2) it
isnt looping and (3) the total amount of data isn't a lot. This is
sufficient for many people but doesn't let you all the possible things that
could be done with server push.

For example, you could have 10 frames of an animation -- 10 GIFs -- that
total 50k. The CGI reads all the GIFs, returns all the data to WebStar
(with the appropriate server push headers between them), and then closes
its connection to the server. Webstar then starts sending all the data to
the browser. This works.

What doesn't work is:
(1) sending too much data - if your animation is 1000 GIFs and totals 2
megs, thats too much data and it will get truncated. How much data you can
send before this problem happens has been a matter of debate, I have found
this limit to be around 50k in my tests. I think I recall someone saying
that it is a function of the memory allocation of the CGI "app", and
raising the memory allocation would raise this limit significantly.

(2) putting delays between each frame, or other timing tricks doesn't work.
The data doesn't begin to get sent to the browser until after the CGI is
finished and closes its connection to the server.

(3) No looping. Obviously, the data would never get sent to the browser.
The CGI has to close the TCP connection before the Web server begins
sending the data to the browser.

These things *can* be done with some other servers on on some other
platforms, using Perl-based CGI's. For example, the Netscape server on DEC
Unix sends data to the browser as the CGI returns it, so the CGI can do
timing tricks, looping, without any time limit or limit of the amount of
data.

Below is a public domain server push script written in Perl. It works on
Unix, and should work on a Mac. You may have to change the \n to a \015 or
a \012.  Enjoy.

-Dave

#!/usr/bin/perl
# Animation Perl Script
# Written by Matt Wright  (http://worldwidemart.com/scripts/)
# Created on: 9/28/95   Last Modified on: 11/21/95
# Version 1.2

#########################################################
# Variables

$times = "1";
$basefile = "/WWW/images/animation/";
@files = ("begin.gif","second.gif","third.gif","last.gif");
$con_type = "gif";

# Done
#########################################################

# Unbuffer the output so it streams through faster and better

select (STDOUT);
$| = 1;

# Print out a HTTP/1.0 compatible header. Comment this line out if you
# change the name to not have an nph in front of it.

print "HTTP/1.0 200 Okay\n";

# Start the multipart content

print "Content-Type: multipart/x-mixed-replace;boundary=myboundary\n\n";
print "--myboundary\n";

# For each file print the image out, and then loop back and print the next
# image.  Do this for all images as many times as $times is defined as.

for ($num=1;$num<=$times;$num++) {
   foreach $file (@files) {
      print "Content-Type: image/$con_type\n\n";
      open(PIC,"$basefile$file");
      print <PIC>;
      close(PIC);
      print "\n--myboundary\n";
   }
}
print "\n--myboundary--\n";

# end of script