Ajax Push Engine 1.0 Beta 5

I talked quickly about APE in a recent post. I recently downloaded a new version of their program and
I’ve installed it successfully and it works much better. Since the first released verison, it has become quite easy, you just have to launch “./build.sh”. I had some problems with the linker on my CentOS system and the mysql libraries. But I solved it by added “-L/var/lib64/mysql” to some line of the Makefile.

How to make the demos work
They are some tiny bugs that took me quite some time to bypass :

  • To use the controller demo, you need to put the modules/conf/inlinepush.conf file into bin. I guess this will be fixed someday soon but still, that’s how it works right now.
  • To use the move demo, you need to change the scripts/main.ape.js file and add this line :
    1
    
    include("examples/move.js");
  • To use the TCPSocket demo, you need to copy the modules/conf/proxy.conf file into bin.

Note : Each time you modify a script file (within the “scripts” directoy of APE), you have to restart the server.

The very interesting javascript backend
This project is very interesting because everything in the backend is handled by some little javascript files, the move example file is this one :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Ape.registerCmd('setpos', true, function(params, infos) {
        if ((!$defined(params.x) || !$defined(params.y)) && (!isFinite(params.x) || !isFinite(params.y))) return 0;
 
        infos.user.setProperty('x', params.x);
        infos.user.setProperty('y', params.y);
 
        // We get the channel
        var chan = Ape.getChannelByPubid(params.pipe);
 
        // And send the position data of the calling user on it
        if (chan) {
                chan.pipe.sendRaw('positions', {'x': params.x, 'y': params.y}, {'from': infos.user.pipe});
        } else {
                return ['109', 'UNKNOWN_PIPE'];
        }
 
        return 1;
});

This is what allows the client to send this kind of request :

1
[{"cmd":"SETPOS","chl":10,"params":{"x":282,"y":38,"pipe":"3dcaa701e8ee3394d65d5f71cd18e428"},"sessid":"b897476d835d12c150fb9fc337c7c93d"}]

If you don’t add the include line, the answer will be something like that :

1
[{"time":"1260123358","raw":"ERR","data":{"chl":10,"code":"003","value":"BAD_CMD"}}]

The “BAD_CMD” reply means that this commands hasn’t be registered by the Ape.registerCmd method. If you come here because that happened to you, just fix it.

For the Controller demo, this is exactly the same. The file is :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Ape.registerCmd("inlinepush", false, function(params, infos) {
        // We check the password ("password" parameter of the "inlinepush.conf" file)
        if (params.password == Ape.config("inlinepush.conf", "password")) {
                // If every request parameters have been correctly defined
                if ($defined(params.channel) && $defined(params.data) && $defined(params.raw)) {
                        // We get the channel
                        var chan = Ape.getChannelByName(params.channel);
                        if (!$defined(chan)) return ["401", "UNKNOWN_CHANNEL"];
 
                        // We send the data (as received) back to the channel
                        chan.pipe.sendRaw(params.raw, params.data);
 
                        return {"name":"pushed","data":{"value":"ok"}};
                } else {
                        return 0;
                }
        } else {
                return ["400", "BAD_PASSWORD"];
        }
})

If you get the the BAD_PASSWORD error response and you’re not sure why, you can change the BAD_PASSWORD line by :

1
return ["400", "BAD_PASSWORD, the right one is :"+Ape.config("inlinepush.conf", "password")];

If you get “BAD_PASSWORD, the right one is :”. There’s a good chance you didn’t move the inlinepush.conf into the bin directory.

Sample communications
Here is a sample chat communication

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Echange CHAT :
--> [{"cmd":"script","params":{"domain":"ape.webingenia.com","scripts":["http://ape.webingenia.com/Source/mootools-core.js","http://ape.webingenia.com/Source/Core/APE.js","http://ape.webingenia.com/Source/Core/Events.js","http://ape.webingenia.com/Source/Core/Core.js","http://ape.webingenia.com/Source/Pipe/Pipe.js","http://ape.webingenia.com/Source/Pipe/PipeProxy.js","http://ape.webingenia.com/Source/Pipe/PipeMulti.js","http://ape.webingenia.com/Source/Pipe/PipeSingle.js","http://ape.webingenia.com/Source/Request/Request.js","http://ape.webingenia.com/Source/Request/Request.Stack.js","http://ape.webingenia.com/Source/Request/Request.CycledStack.js","http://ape.webingenia.com/Source/Transport/Transport.longPolling.js","http://ape.webingenia.com/Source/Transport/Transport.SSE.js","http://ape.webingenia.com/Source/Transport/Transport.XHRStreaming.js","http://ape.webingenia.com/Source/Transport/Transport.JSONP.js","http://ape.webingenia.com/Source/Core/Utility.js","http://ape.webingenia.com/Source/Core/JSON.js","http://ape.webingenia.com/Source/Core/Session.js"]}}]
<-- (useless html response)
 
// We  try some "CONNECT" and then "JOIN" commands with the name "superfc"
--> [{"cmd":"CONNECT","chl":1,"params":{"name":"superfc"}},{"cmd":"JOIN","chl":2,"params":{"channels":"test"}}]
// Error, the nick name is already use
<-- [{"time":"1260119123","raw":"ERR","data":{"code":"005","value":"NICK_USED"}}]
 
// We  try some "CONNECT" and then "JOIN" commands with the name "Florent"
--> [{"cmd":"CONNECT","chl":5,"params":{"name":"Hello"}},{"cmd":"JOIN","chl":6,"params":{"channels":"test"}}]
// This works !
<-- [{"time":"1260119134","raw":"LOGIN","data":{"sessid":"36a60d006d50882d0d2cd6bcfda90cb9"}},
{"time":"1260119134","raw":"IDENT","data":{"user":{"casttype":"uni","pubid":"8b5fec5af11df915d9806a3be4b46c35","properties":{"name":"Hello"}}}},
{"time":"1260119134","raw":"CHANNEL","data":{"users":[{"casttype":"uni","pubid":"8b5fec5af11df915d9806a3be4b46c35","properties":{"name":"Hello"},"level":1},{"casttype":"uni","pubid":"cc03a08f304a75cc133827c6c4b561c8","properties":{"name":"superfc"},"level":1},{"casttype":"uni","pubid":"541e78a0fbfbc08457c800aacccd212d","properties":{"name":"Florent"},"level":1}],"pipe":{"casttype":"multi","pubid":"2b27244bdb42c193d5158e818ec577d0","properties":{"name":"test"}}}}]
 
// We send 
--> [{"cmd":"SESSION","chl":7,"params":{"action":"set","values":{"currentPipe":"2b27244bdb42c193d5158e818ec577d0"}},"sessid":"36a60d006d50882d0d2cd6bcfda90cb9"}]
<-- [{"time":"1260119136","raw":"LEFT","data":{"user":{"casttype":"uni","pubid":"cc03a08f304a75cc133827c6c4b561c8","properties":{"name":"superfc"}},"pipe":{"casttype":"multi","pubid":"2b27244bdb42c193d5158e818ec577d0","properties":{"name":"test"}}}}]
 
// These next requests are long polls with nothing
--> [{"cmd":"CHECK","chl":9,"sessid":"36a60d006d50882d0d2cd6bcfda90cb9"}]
 
// Nothing new
<-- [{"time":"1260119186","raw":"CLOSE","data":{"value":"null"}}]
 
--> [{"cmd":"CHECK","chl":10,"sessid":"36a60d006d50882d0d2cd6bcfda90cb9"}]
<-- [{"time":"1260119211","raw":"CLOSE","data":{"value":"null"}}]
 
--> [{"cmd":"CHECK","chl":11,"sessid":"36a60d006d50882d0d2cd6bcfda90cb9"}]
<-- [{"time":"1260119239","raw":"CLOSE","data":{"value":"null"}}]
 
// We send some text ("hello")
--> [{"cmd":"SEND","chl":19,"params":{"msg":"Hello hello","pipe":"2b27244bdb42c193d5158e818ec577d0"},"sessid":"36a60d006d50882d0d2cd6bcfda90cb9"}]
// And we receive it ("hello")
<-- [{"time":"1260119399","raw":"DATA","data":{"msg":"hello","from":{"casttype":"uni","pubid":"541e78a0fbfbc08457c800aacccd212d","properties":{"name":"Florent"}},"pipe":{"casttype":"multi","pubid":"2b27244bdb42c193d5158e818ec577d0","properties":{"name":"test"}}}}]

If you don’t understand what is long polling, please look at previous post on the subject.

Please not that that the “CLOSE” RAW isn’t some sort of “session closed” message. I’m not sure this it’s what the developer planned but right now it only means that there’s nothing to receive. So if you get that, don’t panic. Everything is working fine.

If you need any help…
Please, don’t hesitate add some question in the comments, I’ll be happy to help you.

5 thoughts on “Ajax Push Engine 1.0 Beta 5”

  1. Hi, I am trying to run the Tools/Check and am getting the following result:

    Running test : Init
    Running test : Loading Client
    Running test : Loading config
    Config values are :

    identifier : ape
    init : true
    frequency : 0
    scripts : http://ape-test.local/ape-jsf/Source/mootools-core.js,http://ape-test.local/ape-jsf/Source/Core/APE.js,http://ape-test.local/ape-jsf/Source/Core/Events.js,http://ape-test.local/ape-jsf/Source/Core/Core.js,http://ape-test.local/ape-jsf/Source/Pipe/Pipe.js,http://ape-test.local/ape-jsf/Source/Pipe/PipeProxy.js,http://ape-test.local/ape-jsf/Source/Pipe/PipeMulti.js,http://ape-test.local/ape-jsf/Source/Pipe/PipeSingle.js,http://ape-test.local/ape-jsf/Source/Request/Request.js,http://ape-test.local/ape-jsf/Source/Request/Request.Stack.js,http://ape-test.local/ape-jsf/Source/Request/Request.CycledStack.js,http://ape-test.local/ape-jsf/Source/Transport/Transport.longPolling.js,http://ape-test.local/ape-jsf/Source/Transport/Transport.SSE.js,http://ape-test.local/ape-jsf/Source/Transport/Transport.XHRStreaming.js,http://ape-test.local/ape-jsf/Source/Transport/Transport.JSONP.js,http://ape-test.local/ape-jsf/Source/Core/Utility.js,http://ape-test.local/ape-jsf/Source/Core/JSON.js
    baseUrl : http://ape-test.local/ape-jsf
    domain : auto
    server : ape.ape-test.local:6969

    Running test : Setting document.domain
    Running test : Checking APE.Config.baseUrl
    APE JSF Version 1.0
    Running test : Contacting APE Server
    Connection etablished but something went wrong. Server response is

    [{“time”:”1262195941″,”raw”:”ERR”,”data”:{“code”:”003″,”value”:”BAD_CMD”}}]

    Something went wrong. If you can’t fix it by yourself post a message on the newsgroups with the output below or join our IRC channel

    Any ideas?

  2. Sorry, I was planning on searching the answer for you and then replying.

    You should take the package for your distribution, it’s the easiest way to get everything working instantly.

    I wasn’t very explicit. “ERR / BAD_CMD” means it somehow couldn’t register some commands. It can come from any little mistakes. The software is still young and doesn’t do much checks.

  3. I am up and running now, at least past the Linux issues. The documentation is a little unclear in some places, but I think I have a basic handle on what’s going on now. Thanks for your reply.

  4. Hi Florent, I’m trying to get my ape server up and running inlinepush commands. I’m able to run most other functions like connect, check, etc. When I try the inlinepush command, I see the BAD_CMD error. I’ve made sure that the inlinepush.js file is included and that the .conf file is in the bin folder like your amazing article suggested.

    I’ve restarted the server and even rebuilt the executable — I’m having no luck at this and I’m sad. Any other suggestions?

    I’m using the latest APE sever and APE_JSF available on Github.
    https://github.com/APE-Project

Leave a Reply

Your email address will not be published. Required fields are marked *