APE Comet Server Local Dev Environment Setup
APE (Ajax Push Engine) is a scalable comet or AJAX push server written in C. It’s great for embedding HTML chat clients or making real-time games without Flash.
I’ve been playing around with APE for a couple different applications. Setting up the demos on a single server that runs both Apache and the APE server is relatively straight forward. However, running the APE server separate from the web server is not as simple.
Here’s my dev environment…
- Web server: Ruby on Rails running locally on my mac at http://0.0.0.0:3000
- APE server: running in a Debian VMWare server at http://192.168.0.99:6969
The production environment is similar with Heroku as the web server and Linode running the APE server.
Here’s what you have to do to get the dev environment setup from scratch…
- Download APE Project
- Follow the APE doc for installing the server
- Create a new rails project and copy the ape-jsf folder into your rails project’s public dir
- Edit /etc/hosts on your mac and add the entries below
- Edit ape-jsf/Demos/config.js as directed below
- Modify JS Request methods to use GET instead of POST
Add to /etc/hosts
192.168.0.99 ape.dummy-domain.com 192.168.0.99 0.ape.dummy-domain.com 192.168.0.99 1.ape.dummy-domain.com 192.168.0.99 2.ape.dummy-domain.com 192.168.0.99 3.ape.dummy-domain.com 192.168.0.99 4.ape.dummy-domain.com 192.168.0.99 5.ape.dummy-domain.com 192.168.0.99 6.ape.dummy-domain.com 192.168.0.99 7.ape.dummy-domain.com 192.168.0.99 8.ape.dummy-domain.com 192.168.0.99 9.ape.dummy-domain.com 0.0.0.0 dummy-domain.com
Edit ape-jsf/Demos/config.js
APE.Config.baseUrl = 'http://dummy-domain.com:3000/ape-jsf'; //APE JSF APE.Config.domain = 'auto'; APE.Config.server = 'ape.dummy-domain.com:6969'; //APE server URL
Last but not least, edit ape-jsf/Tools/Check/index.html and modify all Request calls to use GET instead of POST. By default, MooTools Request object uses POST for XHR requests which will cause a problem with Rails.
this.addTest('Loading Client', function() {
var req = new Request({
'url': '../../Clients/MooTools.js',
'method': 'GET',
'evalResponse': true,
'onComplete': function(resp) {
if (window.APE) this.fireEvent('testComplete', {'sucess': true});
else this.fireEvent('testComplete', {'error': "Can't load client, check the file " + window.location.href.replace('/Tools/Check/', '') + "/Clients/MooTools.js is available"});
}.bind(this)
}).send();
}.bind(this));
The test script should now run properly at http://dummy-domain.com:3000/ape-jsf/Toosl/Check/
APE uses iframe and JSONP hacks to transparently handle javascript subdomain security issues.
If you look at what’s going on in Firebug, you’ll see APE embedding an iframe in the page, setting the iframe domain to dummy-domain.com, and making calls to the APE server through iframe. This trick only works if the main HTML page is on a different sub-domain than the APE server. It will not work for two completely different domains. This is a limitation of Javascript browser security and not APE.
Thanks to the APE dev team for making an awesome comet server!
Aug 21, 2010 @ 03:40:17
Hi there. My chat runs on a VPS with a gig of RAM but it runs into lag issues with around 170 people. I was wondering if you could give me an estimate on how much an ajax chat using real-time code such as provided by http://www.ape-project.org/ would be. Or even http://nodejs.org/ depending on what’s best.
A screenshot of my current chat is http://img408.imageshack.us/img408/4111/chathco.png
What I would require is a similar setup but with the ability to set custom statuses (currently we use that dropdown menu that reads “No Status” to change from a preloaded list.
I’d also need private messaging, user rooms, and a button to take you to a URL like profile.php?user=(their name here) is needed too.
We don’t need to invite or share files.
Sep 23, 2010 @ 19:04:40
Hi David. Sorry for the delay in reply. I’ve been super busy on a project.
APE and node.js scale reasonably well for most applications. Chat tends to be a relatively easy app to scale since chat rooms are typically capped at a few hundred active participants. Each Room can be hosted on different servers. Both APE and node.js should be able to handle thousands of participants per room without any problems. APE claims around 100,000 connections per server, but I haven’t had a chance to do my own performance testing.
The amount of RAM you’ll need per chat room depends on the amount of data you want to keep in memory on the server. One solution to keep memory usage down is to only keep the user lists in memory and store message logs and statuses in a db. Whenever a user types in a new chat message, the message would be sent to the server, broadcast out to active connections, and then stored in a db. When a new user connects, just grab the message log from the db to populate his/her chat window.
You might want to also look into the Lift framework for Scala. It’s being used by Foursquare. Twitter is also using Scala for parts of their backend. Scala scales very well and Lift has support for comet (long pulling javascript) out of the box. The example app in the Lift documentation is a chat app.
Cheers,
Joe
Dec 03, 2011 @ 16:31:43
Why did you use “<a href="http:…" in APE.config.baseUrl?
Dec 19, 2011 @ 13:17:49
Hi joe,
I’m developing an ajax push notification application and trying to integrate ape in my rails application. I followed the steps above but i’m getting this error:
“Can’t set document.domain please check APE.Config.domain value it should be dummy-domain.com”
can you please help me deal with this error?