
Most of us (yes, except for Sander ;-)) are using Facebook. There's a small Facebook chat client in the browser, which makes it possible to chat with your friends.
Did you ever notice how fast this chat is going? I mean, you press enter and 1 second later, the message appears on the other PC.
I think this seems rather normal for a person who doesn't know much about programming, but for a developer, this is rather amazing. Everybody knows "polling": a technique were you refetch some blocks from the server after a period of X seconds. But working with polling means: introducing a certain delay (maximum X seconds).
I'm currently working on a project were we also need real time information. No, it's not a chat, something different. I cannot give much details now (it's all top secret you know ;-)), but I have been playing around with http://www.ape-project.org/.
What is APE?
APE is a full-featured OpenSource solution designed for Ajax Push. It includes a webserver (Comet implementation) and a Javascript Framework. APE allows to implement any kind of real-time data streaming to a web browser, without having to install anything on the client-side.
Why APE is insanely great?
APE, previously named ACE (Ajax Chat Engine), is an awesome piece of software whose development started in early 2006 with the democratization of the AJAX technology. Our product is based on principles and philosophies we care about (Open Source, Accessibility, Future of the Internet). As for that, we think we have created something insanely great.
Only web standards!
APE only uses web standards (with the use of Asynchronous JavaScript and XML (AJAX)). You do not need any plugins to be installed on your web browser, just enjoy!
Push, don't pull!
APE is a Server for pushing real-time data to Rich Internet Applications, no pull! Data is sent, live, to thousands of clients, in a JavaScript socket fashion. It allows you to write real-time web applications without using any client plugins (Java, Flash...).
Usability!
APE works with all of the Internet browsers, it is cross-platform and cross-subdomain. It works on mobile devices, smartphones, video game platforms, as long as they include a web browser.
100% FREE & OpenSource!
The APE Project is 100 % Open Source and FREE for commercial and non-commercial use, released under the GNU Public Licence version 2. We want to contribute to a better web by sharing our technologies.
The Ajax Push Engine Project is divided into two distinct parts. The most central part is our epoll-driven HTTP streaming server, the APE Server. Through the APE Protocol, the APE JavaScript Framework sends and receives the actions on the client side.
The APE server
APE Server is an Comet server implementing the POST and GET methods of the HTTP protocol. It does not replace a regular Web Server (such as Apache, Lighttpd or Nginx), however, the APE Server is only used for AJAX Push.
The APE Javascript framework
Written with the use of the MooTools Library, the APE JavaScript Framework receives information sent by the server (RAWs), handles the data, and sends back the users commands (CMDs). With a very small footprint (~10KB), the APE Framework loads really fast on your web browser, thus it's fully adapted for slow connections such as EDGE or 3G.
The APE protocol
To enable the communication between the Server and the APE JavaScript Framework (or whatever client you want), APE has it's own Protocol. It has a really small footprint, and it's really fast to interpret.
Installation (Ubuntu)
Download file(s)
libmysqlclient15off
$ sudo dpkg -i libmysqlclient15off_5.1.30really5.0.83-0ubuntu3_i386.deb
Install
$ sudo dpkg -i APE_Server-1.0.i386.deb
Configuration21>
Running the server on port 80
To make the APE Server work on a dedicated IP through port 80, you just need to edit the ape.conf file (./bin) as the following:
# ./bin/ape.conf
Server {
port = 80
daemon = yes
ip_listen = <ip to bind APE>
domain = auto
rlimit_nofile = 10000
}
Transfer methods between server/client
APE supports different transport methods:
-
Long Polling: default transport method
-
With long polling, the client requests information from the server in a similar way to a normal poll. However, if the server does not have any information available for the client, instead of sending an empty response, the server holds the request and waits for some information to be available. Once the information becomes available (or after a suitable timeout), a complete response is sent to the client. The client then immediately re-request information from the server.
-
JSONP: for cross domain push
-
This transport method allows APE to work cross domain. For example your APE Server runs on http://ape.yourdomain.com but you also want it to be accessible on any other domain. This can be done using JSONP.
-
XHRStreaming: for better performance and low latency
-
This transport method is similar to long polling, but instead of closing connection when new data arrives, the server keeps the connection open. This only works in browsers based on Gecko or Webkit (e.g. Safari, Chrome, Firefox).
-
WebSockets : Best performances. (FF4, Chrome, Safari 5)
Changing the timeout interval (25s) of the "Long polling" transfer method
[10:42] <Jochus> hi
[10:42] <Jochus> a little question
[10:43] <Jochus> is it correct "Long polling" kills the connection after 25s?
[10:51] <Psoden> it seems that way. If by killing you mean closes current polling and starts another
[10:53] <Jochus> yes, by killing: I mean closing the current polling :-)
[10:53] <Jochus> is it possible to change the timeout?
[11:05] <+Getty> no
[11:05] <+Getty> also you dont want to
[11:05] <+Getty> its like the time the stargate can stand open
[11:08] <Jochus> Getty: ok, thanks!
What is the "x" number in front of the XHR request?
Maybe you already noticed the number before each request sent to the APE server:
http://2.ape.ape-project.org/?
-------^
This number is called frequency. Each time the APE JSF is loaded, the frequency is incremented. This allows the APE Server to detect that the user loaded a new page.
-
If APE JSF is loaded without sessions, the frequency is only used to bypass some browser limitations.
-
If APE JSF is loaded with sessions, instead of sending a connect command when start(); is called, it asks the APE server for the user's session.
The server then sends the Multi and Uni pipes the user was connected to, so the APE JSF will fire multiPipeCreate and uniPipeCreate events.