#!/usr/bin/perl -- # IE streaming server-push problem demonstration ############################### ################################################################################ # This script is meant to demonstrate strange IE behavior when working with # streaming data. When directed to http://localhost:9090/, the browser should # print a page which simply displays the following: # # Awaiting commands... # Connecting... (script should start alerting soon) # Executing command: alert('a' + 0) # Executing command: alert('b' + 0) # Executing command: alert('c' + 1) # Disconnected. # Connecting... (script should start alerting soon) # # Each command should be accompanied by an alert box with the specified message. # The script should print these messages in Firefox, but in Internet Explorer, # the printing of Executing command: is not expected to occur since IE is not # expected to allow access to the responseText until the server has closed the # socket. It /should/, however, signal alerts, but this is not happening. # # After the server prints the three commands, it closes the socket. The # client re-establishes the connection and it begins again. Only at this point # does IE print the alert messages. use IO::Socket; use strict; $| = 1; my $sock = new IO::Socket::INET( LocalPort => 9090, Proto => 'tcp', Listen => SOMAXCONN, Reuse => 1 ); while (my $client = $sock->accept) { print "\nReceived a connection\n"; my $request = <$client>; # PRINT THE COMET SCRIPT SNIPPETS ############################################ # This code is run when connecting to localhost:9090/?ajax if ($request =~ /comet/) { print $client "HTTP/1.0 200 OK\nContent-type: text/html\n\n"; $_ = int(rand() * 5); print "a $_\n"; print $client "\n"; sleep(2); # wait 2 seconds $_ = int(rand() * 5); print "b $_\n"; print $client "\n"; sleep(2); # wait 2 seconds $_ = int(rand() * 5); print "c $_\n"; print $client "\n"; } # PRINT THE HTML PAGE ######################################################## # This code is run when connecting to localhost:9090 else { print $client "HTTP/1.0 200 OK\nContent-type: text/html\n\n"; print $client qq{