type of stream selection added
[brisk.git] / web / xynt_test01.php
1 <?php
2
3 $transs = array( "iframe", "xhr", "htmlfile" );
4 if (!isset($f_trans))
5     $f_trans = $transs[0];
6
7 if (!isset($f_test))
8     $f_test = 1;
9
10
11 function mop_flush()
12 {
13     for ($i = 0; $i < ob_get_level(); $i++)
14         ob_end_flush();
15     ob_implicit_flush(1);
16     flush();
17 }
18
19 $escpush_from = array("\\", "\"");
20 $escpush_to   = array("\\\\", "\\\"");
21 function escpush($s)
22 {
23     GLOBAL $escpush_from, $escpush_to;
24
25     return str_replace($escpush_from, $escpush_to, $s);
26 }
27
28 if ($isstream == "true") {
29
30     require_once("Obj/transports.phh");
31
32
33     if (isset($transp) && $transp == "xhr") {
34         $transp = new Transport_xhr();
35     }
36     else if (isset($transp) && $transp == "htmlfile") {
37         $transp = new Transport_htmlfile();
38     }
39     else {
40         $transp = new Transport_iframe();
41     }
42     $header_out = array();
43
44     $init_string = "";
45     for ($i = 0 ; $i < 4096 ; $i++) {
46         if (($i % 128) == 0)
47             $init_string .= "\n";
48         else
49             $init_string .= chr(mt_rand(65, 90));
50     }
51
52     $body = $transp->init("plain", $header_out, $init_string, "", "0");
53
54     foreach ($header_out as $key => $value) {
55         header(sprintf("%s: %s", $key, $value));
56     }
57     print($body);
58     mop_flush();
59
60     for ($i = 1 ; $i < 10 ; $i++) {
61         $chunk = $transp->chunk($i, sprintf("\$('container').innerHTML = '%d';", $i));
62         print($chunk);
63         mop_flush();
64         
65         // exit(123);
66         sleep(1);
67     }
68     exit;
69 }
70 ?>
71 <html>
72 <head>
73 <title>XYNT TEST01</title>
74 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
75 <script type="text/javascript" src="xynt-streaming.js"></script>
76 <script type="text/javascript" src="commons.js"></script>
77
78 <!-- <script type="text/javascript" src="myconsole.js"></script> -->
79
80 <script type="text/javascript"><!--
81      var sess = "for_test";
82      var stat = "";
83      var subst = "";
84      var gst = new globst();
85      window.onload = function() {
86      xstm = new xynt_streaming(window, "<?php echo "$f_trans";?>", null /* console */, gst, 'xynt_test01_php', 'sess', sess, null, 'xynt_test01.php?isstream=true', function(com){eval(com);});
87      /*     xstm.hbit_set(heartbit); */
88      xstm.start();
89  }
90  //-->
91 </script>
92 </head>
93 <body>
94 <div>
95 <?php
96
97 printf("<table>");
98 for ($test = 1 ; $test <= 2 ; $test++) {
99     printf("<tr>");
100     foreach ($transs as $trans) {
101         printf("<td style=\"padding: 8px; border: 1px solid black;\"><a href=\"?f_trans=%s&f_test=%d\">Test %s %02d</a></td>", $trans, $test, $trans, $test);
102     }
103     printf("</tr>\n");
104 }
105 printf("</table>");
106 printf("<br>[%s]<br>Test: %d<br>", $f_trans, $f_test);
107 ?>
108 </div>
109 <div id="container">
110 BEGIN
111 </div>
112 </body>
113 </html>