• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 220
  • Last Modified:

Streaming HTML

I remember about a year ago, there was a chat site that used HTML as it's medium.   It was somewhat impressive in one area, which was that it had Streaming Chat or more appropriately the chat's posts werealways being received and never stopped until a certain limit hit a which then stopped the stream.

I have been trying to reproduce this with no luck.    I have seen similar "streaming" effects when you downloaded a large HTML file and had to wait.   Yet, generating normal HTML will not allow you to do this simply using a while loop and sleep (it shows nothing whatsoever, not even a simple print between a while).  

I was looking into a server push operation.  But it seems (at least in the CGI::Push module for Perl) that it can display multiple pages and not simply a very long stream.   Anyone have a chance to implement such a scheme using preferably Perl?
0
mfoster
Asked:
mfoster
  • 3
  • 3
1 Solution
 
ercisCommented:
to get browser to show start of page, before sending has finished can use fflush(stdout), but it depends on Apache version
0
 
mfosterAuthor Commented:
Perl is a bit higher level then C/C++ in terms of programming languages.   Now does this require manipulation of the Apache server itself either using a module or is there a way to make the programming language tell apache to flush?
0
 
ercisCommented:
imho it was Apache 1.3.9 or 1.3.6 which sends output to browser if CGI flushes stdout. prior versions of Apache waits until CGI prog exits ...
0
Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

 
mfosterAuthor Commented:
I have version 1.3.11 compiled and installed.  Now all I need to know is how to make my CGI script tell Apache to flush to output.  Anyone use Perl for this?
0
 
ercisCommented:
look at Perl manual - for command on flushing output.
or compile and try this C prog:

#include <stdio.h>

int main(void)
{
  int i;

  printf("Content-type: text/html\n\n");
  printf("<html>\n");

  for (i=0; i<10; i++)
  {
    printf("<h2> TEXT #: %d </h2>\n", i);
    fflush(stdout);
    sleep(3);
  }

  printf("</html>\n");
}
0
 
mfosterAuthor Commented:
Turns out you set the autoflush bit on the STDOUT filehandle to correct the problem.  Quite interesting, as it actually calls fflush() for you after every print.  

I added the code below for anyone interested.


# Filehandle control
use FileHandle;

# Flush standard output
autoflush STDOUT 1;

# Make sure change takes place
print "";

# Display of streaming HTML information
print $cgi->start_html();
   for (my $count=0; $count < 10000; $count++)
   {
           print "<P>$count</P>";
    }

print $cgi->end_html();
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now