I janna,
Thanks for your detailed email. Don't worry, nobody will bite you here :)
First :
Did you know that listening on a "low level" socket is not required to
make APE aware of external app? Indeed, you can just do something like the
following :
Ape.registerCmd('foo', false, function(params, cmd) {
});
And call it with (http) :
http://ape.domain.com/?[{"cmd":"foo","params":{"x":"y"}}]
The second arg of registerCmd : "false" tell APE to not check for the user
to be logged in in order to execute the command.
So, if your external app can speak HTTP, it would be more easier.
In the case where you want to use socket (for some reason), you need to
design a little protocol on top of it.
Check this :
http://www.ape-project.org/wiki/index.php/How_to_build_a_serverside_JS_module#Server
Giving : {flushlf: true} as third argument to Ape.sockServer() can help
you to design a simple "end of line"-based protocol (the data is only
reported when hiting a \n).
I don't really understand your second point :
> send commands/data from the browser to that same socket so that it
> can then be routed out to the external source
Why "same socket"? The script can be seen as a whole application, which
mean that you can do something like :
var socket = new Ape.sockServer(6971, "127.0.0.1", {flushlf: true});
socket.onRead = function(client, data) {
/* tokenize you data somehow */
/* getChannelByName or whatever pipe source */
Ape.getChannelByName(some_token_from_data).pipe.sendRaw('hello',
{'a':'b'});
}
}
On Tue, 15 Mar 2011 11:59:40 -0700 (PDT), janna <[email protected]>
wrote:
> Hello all,
>
> First, I am very much a newbie so please bear with me.
>
> Over the last number of weeks, I have been pleased with how far I have
> been able to get with APE, from successfully getting all of the demos
> to work all the way up to installing the latest Git versions. Much of
> it has been trial and error and I have found this group, the
> documentation and wiki on http://www.ape-project.org/ and other
> information I have been able to source on the web invaluable. It has
> allowed me to begin to successfully adapt the Chat demo for one of our
> needs, by slowly but surely gathering bits and pieces of information
> from examples rather than totally understanding all the aspects of
> javascript (which I surely don't yet).
>
> However, over the last number of days I have been absolutely stumped
> at understanding how to make use of sockets to get data from an
> external source up to the browser while also supporting commands going
> back the other way.
>
> I was able to find this post from Anthony which was great as it
> provided a detailed explanation
> as to how to implement a connection between the APE server and the
> outside world, (without any assumptions that the reader will know how
> to fill in the blanks--or even know that there are blanks in the
> explanation that might need to be filled in!). It works perfectly for
> our needs and I am just trying to build on it:
>
>> > On Feb 8, 5:59 pm, Anthony Catel <[email protected]> wrote:
>
>> > > In fact, you can do this without any PHP code, just by using linux
>> > > tools :
>
>> > > First :
>
>> > > - write a simple server-side JS script to bind APE on a special
>> > > socket :
>
>> > > Ape.addEvent("init", function() {
>> > > var socket = new Ape.sockServer(6971, "127.0.0.1");
>> > > socket.onRead = function(client, data) {
>> > > Ape.log(data);
>> > > }
>
>> > > });
>
>> > > - run this command line :
>
>> > > $ tail -f your_file | netcat 127.0.0.1 6971
>
>> > > This way, every file changes on "your_file" are reported to APE via
>> > > the
>> > > socket.
>
>> > > Anthony
>
> To take this data and push it to the client's browser, I have tried to
> adapt and use proxy.js, I have read over and over again the various
> explanations on the APE website that list sockClient and sockServer
> and the callbacks and functions that relate to them and I've lost a
> lot of hair over the last while as absolutely nothing has worked for
> me. I am getting used to firebug error messages and "BAD PARAMS" and
> am not sure whether I am "this close" to getting it or whether I have
> gone down yet another one of the dozen forks in the road that end up
> being dead ends.
>
> So, would someone be so kind (please!) as to lay out the actual script
> that I would need to:
>
> 1) push data that is being received from the external source (via
> Anthony's example) to all users' browsers
> 2) send commands/data from the browser to that same socket so that it
> can then be routed out to the external source
>
> Thanks in advance to anyone who can help me out. I am excited as to
> the potential of APE and yet I just can't get this part working.
--
You received this message because you are subscribed to the Google
Groups "APE Project" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/ape-project?hl=en
---
APE Project (Ajax Push Engine)
Official website : http://www.ape-project.org/
Git Hub : http://github.com/APE-Project/