[Klone-users] Klone using server push
Stefano Barbato
barbato at koanlogic.com
Tue Jul 8 17:19:43 EDT 2008
Hi Andre,
KLone buffers the first 4096 bytes to give users the opportunity to
modify header fields even after a few bytes have been written out with
io_printf or io_write. You can for example use the response_redirect
even after io_prints:
<%
io_printf(out, "result 1");
io_printf(out, "result 2");
io_printf(out, "result 3");
/* then if an error occurred you can still modify http header */
if(error_condition)
response_redirect(response, "/error.kl1");
%>
The buffer is implemented as a filter attached to the response_t I/O
object so you can avoid such buffer removing such filter and
explicitly call the response_print_header() function (if you want an
HTTP header at least). Here's the code:
<%
...
response_set_field(response, "Expires:","Mon, 26 Jul 1997 05:00:00
GMT");
io_codecs_remove(response_io(rs));
response_print_header(response);
io_printf(out, "---ThisRandomString---\n");
...
%>
Take a look to the "Message Channel" KLone demo application that opens
and keep opened a bidirectional channel between client and server:
http://koanlogic.com/download/klapp-msgchan-1.2.2.tar.gz
It's built on Flash XmlSocket component and a custom easy library we
wrote (see msgchan.h).
bye!
s
On 08/lug/08, at 19:32, Andre Puschmann wrote:
> Hi all,
>
> I am trying to use a server push technique to avoid client side
> polling
> for data.
> I am not sure if I am doing something wrong. For some reason Klone
> sends
> all 4 "packets" in one single bunch. Well, at least wireshark
> reports this!
> Seems like io_flush doesn't work?!
>
> Here is my sample code:
>
> <code>
> <%!
> #include <stdio.h>
> %><%
> int i;
>
> response_set_content_type(response,
> "multipart/x-mixed-replace;boundary=---ThisRandomString---");
> response_set_field(response, "Pragma:", "no-cache");
> response_set_field(response, "Cache-Control", "no-cache, no-store,
> must-revalidate");
> response_set_field(response, "Expires:", "Mon, 26 Jul 1997 05:00:00
> GMT");
>
>
> io_printf(out, "---ThisRandomString---\n");
>
> for (i = 1; i < 5; i++)
> {
> io_printf(out, "Content-type: text/html\n\n");
> io_printf(out, "<h2>part %d</h2>\n", i);
> io_printf(out, "---ThisRandomString---\n");
> io_flush(out);
> sleep(1);
> }
> %>
> </code>
>
> Using the built-in cgi works for a shell script. Also here's the code
> for that one:
>
> <code>
> #!/bin/sh
> echo "HTTP/1.0 200"
> echo "Content-type:
> multipart/x-mixed-replace;boundary=---ThisRandomString---"
> echo ""
> echo "---ThisRandomString---"
> while true
> do
> echo "Content-type: text/html"
> echo ""
> echo "time: "
> date
> echo "---ThisRandomString---"
> sleep 5
> done
> </code>
>
>
> Comments are welcome!
>
> Best regards,
> Andre
>
> _______________________________________________
> Klone-users mailing list
> Klone-users at koanlogic.com
> http://koanlogic.com/cgi-bin/mailman/listinfo/klone-users
>
More information about the klone-users
mailing list