Forum OpenACS Development: streaming ajax based chat

32: streaming ajax based chat (response to 1)
Posted by gustaf neumann on
i have committed a new delivery protocol for chat, which is much faster and less resource demanding.

The current xowiki chat and the chat package in the ajax variant are based on a polling interface. This means that the browser asks every n seconds (per default all 5 seconds) whether there are updates available and displays it accordingly.

The new streaming ajax based variant behaves like downloading a large file when subscribing to a channel. The client opens a connection to the server and reads piecewise the information back. Therefore there is no 5 second gap and no polling necessary. In the plain aolserver, this approach would not be reasonable, since a connection thread would be blocked for every user participating in a chat. aolserver would soon run out of connection threads. I have solved this problem via background delivery thread described already in
With the streaming interface, a client can subscribe to a channel identified by a name, and some other client can broadcast to all users subscribed by the channel. in case of the chat, the channel identifier is simply chat+$chat_id. The streaming chat interface requires libthread and a small patch for the aolserver (see link above). It does currently not work for safari, since - as it looks to me - safari allows only one xmlhttp object concurrently active (strange enough, i did not find complaints about this on the web).

While the polling ajax chat uses xml for coding the messages, the streaming variant uses JSON enoding.

With the current implementation the same chat can be used simultanously with the polling and streaming interface from different clients. The login proc tries to make a clever guess and uses the streaming interface only, when the browser is capable for multiple xmlhttp connections and when the backend has libthread.

In order to try the streaming interface, use firefox and insert into an xowiki object the content:

proc content {} {
::xowiki::Chat login -chat_id 22
In order to force the polling interface, use e.g.
::xowiki::Chat login -chat_id 22 -mode polling

The chat package is still using the polling interface only.
If you want to use thre streaming interface please update xotcl-core, xowiki and xotcl-request-monitor (if you have it installed).

Posted by gustaf neumann on
The "streaming" mode described above does not work with IE. MSIE flags correctly readystate ==3 when partial data arrives, but it does not allow to access the response text (like e.g. in firefox).

so i have defined yet another delivery interface for streaming data via ajax that seems to be quite robust: instead of sending JSON encoded java script objects, it uses now a hidden iframe that recieves a text/html file in streaming mode, which includes SCRIPT-tags containing the javascript calls. i called this mode "scripted-streaming". scripted-streaming works with Firefox, Safrari and IE.

The biggest disadvantage of scripted-streaming over streaming is that while the iframe loads (always) the activity indicator spins, which makes me nervous. so, when libthread is available, firefox uses "streaming" mode, the other browsers use "scripted-streaming" mode. When no libthread is available, "polling" mode is used for all browsers. One can certainly force the mode by specifying it as shown above.

xowiki chat is at least a study how to use AJAX with oacs in three different ways.

Posted by gustaf neumann on
To make things clearer: The streaming modes require the background delivery thread (sending large files asynchronously in the background without blocking connection threads), which requires libthread and a small patch for the aolserver (extending ns_conn)

This is described in where the version numbers are outdated. get the actual code from cvs, not the apm packages. The file contains as well the description for installing libthread...

guess, i should move this info to