APE – An Introduction

APE (AJAX Push Engine) is basically a daemon which acts as a proxy between your client and the HTTPD. It allows thousands of users to exchange real time information through your existing web browser, no reloading and no plug-ins – a web developers dream.

From the APE website:

The first and most central part of APE is our epoll-driven HTTP server entirely written in C, which provides patterns such as XHR long-polling(cross browser), forever frame and many more. The server can be extended using modules, which can be written in both C and Server-Side JavaScript (pending).

The second part of APE is the Javascript Framework based on MooTools that deals with the APE protocol. We’ve put a lot of effort into making iteasy to “hook” into this framework. This enables our users to decide what Javascript framework they want to develop in, regardless of the choice we’ve made.

You can think of APE as reverse AJAX (much like Comet). Traditionally clients request information from the server and the server sends this information to the client for processing. APE can send information direct to clients’ browser, without the need of requesting it, resulting in less bandwidth and lower latency. You can read more upon the technologies behind APE here.

Sounds good? Great, let’s get started! You’ll need a Linux box (Windows not yet supported) with Apache installed and configured, GNU Make, GCC 3.4 and glibc. You’ll also need GIT to download the APE package. Optionally, install PHP and MySQL.

  1. Install the above packages with your distrubtions package manager. If you’re using Arch Linux you can simply do:
    pacman -Sy apache php mysql phpmyadmin glibc make gcc git
  2. Download the APE Server and APE JSF (JavaScript Framework) via GIT:
    git clone git://github.com/APE-Project/APE_Server.git
    git clone git://github.com/APE-Project/APE_JSF.git
    cd APE_Server

    This will create two directories, APE_Server and APE_JSF.

  3. Let’s compile APE and it’s modules:
    make && make install
    cd modules
    make

    Easy, huh?

  4. Edit ape.conf in bin/ – I just changed the user / group and daemon options. My ape.conf looks like:
    uid {
            # "aped" switch to this user/group if it run as root
            user = http
            group = http
    }
    
    Server {
            port = 6969
            daemon = yes
            ip_listen = 0.0.0.0
            ip_local = 127.0.0.1
            domain = ape-test.local
            rlimit_nofile = 65536
    }

    If your testing this over the Internet (i.e dedicated server) change the ip_listen and ip_local variables respectively.

  5. Configure Apache by loading mod_proxy, mod_proxy_http and mod_rewrite. These come with the Apache package in Arch Linux, but you may have to download them separately for your distro:
    LoadModule proxy_module modules/mod_proxy.so
    LoadModule proxy_http_module modules/mod_proxy_http.so
    LoadModule rewrite_module modules/mod_rewrite.so

    Change your Listen and ServerName vars:

    Listen 192.168.10.151:80 #your local/external IP:port
    ServerName ape.ape-test.local:80 #ape.yourdomain.com:80

    You may need to add this to the bottom of your config (or proxy.conf):

    ProxyRequests On
    
            Order deny,allow
            Deny from all
            Allow from 192.168.10.151
  6. Update your DNS. If your testing APE locally just add these to /etc/hosts
    192.168.10.151  ape.ape-test.local      ape #your local/external IP
    127.0.0.1       ape.ape-test.local      ape
    127.0.0.1 0.ape.ape-test.local
    127.0.0.1 1.ape.ape-test.local
    127.0.0.1 2.ape.ape-test.local
    127.0.0.1 3.ape.ape-test.local

    if your testing over the Internet make sure you add the appropriate A records for your domains

  7. Setting up the directory structure and files. cd into the APE_JSF directory we downloaded from GIT and move all the files/folders within there to your WWW folder (Apaches DocumentRoot).
    Edit the file Demos/config.js. Mine looks like:

    APE.Config.baseUrl = 'http://ape.ape-test.local/Source'; //APE JSF
    APE.Config.domain = 'ape-test.local'; //Your domain, must be the same than the domain in aped.conf of your server
    APE.Config.server = 'ape.ape-test.local'; //APE server URL
  8. Starting and testing APE.
    cd /path/to/your/aped
    ./aped

    Open the following URL: http://0.ape.ape-test.com/?script&it_works&anticache (change if differant) and view the source, if you see

    document.domain="ape-test.local"

    it works!

Congratulations, you now have a full working APE server. You can try out the demos in the Demos\ directory and be amazed! My next post will be on using jQuery with the APE JavaScript Framework – stay tuned :)

Share

Related posts:

  1. Using jQuery With APE
  2. Using jQuery with APE – an OOP approach with the DUI
  3. Diving into APE modules and the JSF – creating topics for channels
  4. EsenAPE – send and receive SMS in real time using APE, jQuery, PHP and libape_controller
  5. Using jQuery With APE – change the background-color with PHP

11 Responses to “APE – An Introduction”

  1. Konstantin Mirin  on June 4th, 2009

    Cool thing. Will give it a try nearest time when I have a break between projects.
    Thanks for sharing!

    Reply

  2. Using jQuery With APE | Paul's Blog  on June 8th, 2009

    [...] going to test jQuery by making a simple demo using APE (see my setup guide here). Users will be able to change the background color of the document, this will then be sent to APE [...]

    Reply

  3. Paul's Blog » Introducing PubNub – the new cloud-hosted service for real-time messaging  on January 9th, 2011

    [...] is a new real-time cloud-based subscribe/publish API, it’s basically a hosted version of APE but we require no servers, minimal setup and a cross-platform API including JS, PHP and C# – [...]

    Reply

  4. Nico  on February 28th, 2011

    Hello,
    I’ve setup ape on Centos server 5.5 via Plesk 9.5, i’ve gone through the documentation over and over and i can’t find where my problem is.
    I test the configuration I recieve the error message “Can’t Contact Ape Server. Please Check that your Ape Server is Running and the following url is pointing to your APE server: http://0.ape.project.fr:6969.

    > I created the DNS :
    ape.project.fr A xx.xx.xx.xx
    *.ape.project.fr CNAME ape.project.fr

    > In my virtual host i have this (it’s generated by Plesk, i didn’t update anything)

    ServerName comet.www.youcent.fr:80
    DocumentRoot /var/www/vhosts/domain/subdomains/ape.project/httpdocs
    ….

    in my httpdocs i have the folder ape_jsf and ape_server

    > conf of ape server

    Server {
    port = 6969
    daemon = no
    ip_listen = xx.xx.xx.xx
    domain = domain.fr
    rlimit_nofile = 10000
    pid_file = /var/run/aped.pid
    }

    > conf of jsf

    APE.Config.baseUrl = ‘http://ape.project.fr/ape_jsf'; //APE JSF
    APE.Config.domain = ‘domaine.fr’;
    APE.Config.server = ‘ape.project.fr:6969′; //APE server URL

    What do I need to change in order to fix this?

    Many thanks

    Reply

    • Eli  on May 17th, 2011

      you still having trouble?

      Reply

  5. Nico  on May 17th, 2011

    No thanks !

    Reply

  6. Jus  on June 17th, 2011

    Hi, what did you do to fix this? Does this mean that you have to use a domain which has a valid DNS record? I am getting a similar issue in trying to test this, but I have the domain set to an IP address. ie. 192.168.2.27

    So, when it tries to connect to the server on http://0.192.168.2.27:6969 it obviously fails. Does it have to be bound to a domain name?

    Reply

    • s2xi  on June 17th, 2011

      Because your on a local server, you need to use your actual ip address along with the port.

      Reply

  7. eve  on June 24th, 2011

    Hi, i want to ask about 0.ape.ape-test.local.. is there anyway that i can change the “0″ into alphabet (a,b,c, so on)? bcoz i want to host the project and it can work with number.. any idea? thanks before

    Reply

    • Paul Price  on July 1st, 2011

      Hi Eve, that is more than possible as long as you make sure your DNS records reflect it.

      Reply

  8. ronald  on November 22nd, 2011

    I’m having trouble following your instruction, I was able to git all needed files and start compiling it. cd APE_Server and execute this command make && make install… this what I get

    gcc: ./deps/udns-0.0.9/libudns.a: No such file or directory
    In file included from src/../modules/plugins.h:41,
    from src/plugins.h:27,
    from src/entry.c:22:
    src/../modules/../src/events.h:28:23: error: configure.h: No such file or directory
    In file included from src/sock.c:36:
    src/events.h:28:23: error: configure.h: No such file or directory
    In file included from src/../modules/plugins.h:41,
    from src/plugins.h:27,
    from src/users.c:35:
    src/../modules/../src/events.h:28:23: error: configure.h: No such file or directory
    In file included from src/../modules/plugins.h:41,
    from src/plugins.h:27,
    from src/channel.c:28:
    src/../modules/../src/events.h:28:23: error: configure.h: No such file or directory
    In file included from src/../modules/plugins.h:41,
    from src/plugins.h:27,
    from src/plugins.c:22:
    src/../modules/../src/events.h:28:23: error: configure.h: No such file or directory
    In file included from src/../modules/plugins.h:41,
    from src/plugins.h:27,
    from src/raw.c:27:
    src/../modules/../src/events.h:28:23: error: configure.h: No such file or directory
    In file included from src/events.c:22:
    src/events.h:28:23: error: configure.h: No such file or directory
    src/events.c: In function âevents_freeâ:
    src/events.c:47: error: âstruct _fdeventâ has no member named âeventsâ
    In file included from src/event_kqueue.c:22:
    src/events.h:28:23: error: configure.h: No such file or directory
    In file included from src/event_epoll.c:22:
    src/events.h:28:23: error: configure.h: No such file or directory
    In file included from src/event_select.c:25:
    src/events.h:28:23: error: configure.h: No such file or directory
    In file included from src/dns.c:42:
    src/events.h:28:23: error: configure.h: No such file or directory
    make: *** [aped] Error 1

    Reply


Leave a Reply