pi.comet.How it works
Summary
Understanding the push technology.
General Logic
To accomplish client-server data communication, the server needs wait on the request.The generalized algorithm for the serverside programming is as follows:
for i from 0 to 15
print unixtime
flush()
sleep()
Cross Browser Output
The data which will be printed has to be put into a specific format due to development of special techniques for different browsers.Because of pi.comet sends two additional query string parameters on transport.These are;
- PICometMethod: Comet method.
- PICometName: Event name for Opera Browser.
The cross browser algorithm that prints with the values above is;
if parameter("PICometName")==2 then
header["ContentType"] = "application/x-dom-event-stream"
else
header["ContentType"] = "text/html"
end if
for i from 0 to 15
case parameter("PICometMethod") of
1: "<comet>%s</comet>"%(unixtime)
2: "Event: %s\ndata:%s"%( parameter("PICometName"), unixtime )
3: "<script>parent.PIComet.event.push(\"%s\")</script>"%(unixtime)
endcase
flush()
sleep()
To complete pushing operation easily, you may either create your own class or download and use one of the available class immediately.Please visit the
Push Classes page to check for available classes.