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…

  1. Download APE Project
  2. Follow the APE doc for installing the server
  3. Create a new rails project and copy the ape-jsf folder into your rails project’s public dir
  4. Edit /etc/hosts on your mac and add the entries below
  5. Edit ape-jsf/Demos/config.js as directed below
  6. 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!

Building the Wikitude Sample App for iPhone 4

I’m new to iPhone development but wanted to see how quickly I could build an augmented reality prototype for a simple AR treasure hunt game.  I looked at the APIs for Layar, ARToolKit, Junaio, and settled on Wikitude for this test.  Wikitude provides an augmented reality library that you can drop into your iPhone project in less than an hour.  Bad ass.  Assuming you’re not an iPhone dev n00b like me.  Then it takes you three hours.

If you’ve never tried to build a downloaded sample app, hopefully this guide will save you a couple hours of futzing around with plist and project configuration.

I’m using XCode 3.2.3 with the iOS SDK 4.0.1 and targeting an iPhone 4 device connected to my MacBook Pro.

Getting Started

  1. Download the Wikitude iPhone API and unzip the sample app
  2. Open WikitudeAPI-SCM-Test.xcodeproj in XCode
  3. Click “Build and Run” on the XCode toolbar

You’ll probably get one or more of the following errors:

  • There is no SDK with the name or path ‘iphoneos3.1.2′.
  • Code Sign error: a valid provisioning profile matching the application’s Identifier ‘com.companyname.productname’ could not be found

Time for to fix the sample app configuration.  Search paths, target architecture, base SDK, and code signing will all need to be changed in order to successfully build the project.

Before you go any further, make sure you’re set up through the iPhone Dev Center Provisioning Portal to sign code.  The Wikitude API will not run in a simulator, and building for devices requires a valid code signing identity.  You can apparently use the XCode Organizer to create your code signing profiles.  However, I kept getting an unexpected error and ended up doing everything through the web portal.  For simplicity, I created a wildcard domain (com.simple10.*) for the App ID so that I can use the same provisioning profile for other apps.

Once your provisioning profile is ready to go, it’s time to fix the XCode project configuration so the sample app will build.

Fixing Config Options in XCode

Open the project info build options panel by double clicking on WikitudeAPI-SCM-Test project.

Wikitude Sample App Configuration

Make the following changes to the build options…

Architectures

  • Architectures: Standard (armv6 armv7)
  • Base SDK: iPhone Device 4.0
  • Build Active Architecture Only: [checked]

Code Signing

  • Code Signing Identity > Any iPhone OS Device: [select your provisioned profile]

Open the targets build option panel by expanding the Targets tree and double clicking on WikitudeAPI-SCM-Test.

Wikitude Sample App Config Screen 2

Make the following changes to the target build options…

Search Paths > Library Search Paths

  • Remove “$(SRCROOT)/../WikitudeAPI-SCM/build/Debug-iphoneos”
  • Remove “$(SRCROOT)/../../../Desktop/WikitudeAPI”

Open WikitudeAPI_SCM_Test-Info.plist and edit the bundler identifier to match the domain used in your provisioning profile.

Wikitude Sample App Screen 3

Finally, make sure that Active Architecture setting in the build target drop down menu is set to armv6.

Click Build and Run.  The app should build, deploy, and automatically run on your connected iPhone.

Macports to Homebrew

Thanks to a new macbook pro with a clean OS install and minimal dev tools, I made the switch from macports to homebrew.  Easy enough with a few caveats.

The homebrew people recommend uninstalling macports first.

Then install homebrew.

Everything worked fine until trying to ‘brew install imagemagick‘.  The compilation fails.  This seems to be a common problem.

The quick solution was to ‘sudo brew install imagemagick‘.  Compilation worked.  However, sudo installing ghostscript after installing imagemagick failed to find the jpeg lib which was previously installed without sudo.  Yuck!

The final solution was to brew uninstall all image packages (jpeg, libtiff, ghostscript, etc.) and then run the following…

$ brew list
git
$ sudo brew install ghostscript
$ sudo brew install imagemagick
$ brew list
ghostscript    imagemagick    jpeg
little-cms     git        jasper        libtiff
pkg-config

I’m not sure if it’s possible to install ghostscript and imagemagick without using sudo.  I tried several times, and in the end sudo worked where other attempts failed.