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

[MacPerl] Server push



Has anybody ever played with server push or "the poor man's animation", as
some people call it? Could you provide me with a simple example?

I have copied the following code from a book, but not managed to make it
work since I am no MacPerl expert:

#!perl

require "flush.pl";

print "HTTP/1.0 200\n";
print "Content-type: multipart/x-mixed-replace;boundary=ARandomString\n\n";

print "--ARandomString\n";

while (1) {
                                                print "Content type:
image/gif\n\n";
                                        open (IMAGE, ">ClockUp.gif");
                                                while (read(IMAGE, $buf,
18000)) {
                                                print $buf;
                                                }
                                                close (IMAGE);
                                                print "\n--ARandom\n";
                                                &flush(STOUT);
                                                sleep(1);

                                                print "Content type:
image/gif\n\n";
                                        open (IMAGE,
"<pictures/ClockRight.gif");
                                                while (read(IMAGE, $buf,
18000)) {
                                                print $buf;
                                                }
                                                close (IMAGE);
                                                print "\n--ARandom\n";
                                                &flush(STOUT);
                                                sleep(1);

                                                print "Content type:
image/gif\n\n";
                                        open (IMAGE, "<pictures/ClockDown.gif");
                                                while (read(IMAGE, $buf,
18000)) {
                                                print $buf;
                                                }
                                                close (IMAGE);
                                                print "\n--ARandom\n";
                                                &flush(STOUT);
                                                sleep(1);

                                                print "Content type:
image/gif\n\n";
                                        open (IMAGE, "<pictures/ClockLeft.gif");
                                                while (read(IMAGE, $buf,
18000)) {
                                                print $buf;
                                                }
                                                close (IMAGE);
                                                print "\n--ARandom\n";
                                                &flush(STOUT);
                                                sleep(1);

}

Philippe de Rochambeau