Why do I need to set a 'channel' on my .load function?

69 views
Skip to first unread message

Micael Ribeiros

unread,
Apr 5, 2012, 9:42:09 AM4/5/12
to APE Project
Hello,

I'm building a multichannel chat system so I need to save the private
"client-server" pipe that communicates between the user and server
(only) on a variable, on each of the pipe's of the channel the user is
in on other variables. I've managed to do everything but I was using a
'global' channel to communicate between the client and server, I have
recoded it but now I dont seem to get a hold of the private 'client-
server' pipe if I dont use the 'channel' option on the client load
function.

On which function do I retrieve/create the "client-server" pipe, on
server I'm guessing it gets automatically stored on user.pipe but what
about the client, on which function can I retrieve it?

Do I need to set the pipe on the server (so it transfers it to the
client?), it does not set automatically? I tried sending a raw command
to the client on the onConnect, the client receives it, but the 'pipe'
variable on the client is empty. When does it 'initiate' or where do I
get/set it?

Can I do this manually or do I really have to set that channel on the
load options? Or am I wrong and the messages sent on the 'global'
channel pipe and kept between the server and the client and not shared
with other users?

Thank you in advance for any response,
Regards

Pablo Tejada

unread,
Apr 5, 2012, 9:52:39 AM4/5/12
to ape-p...@googlegroups.com
I have an example and some code i would like to share with you but is
sitting on my desktop at home. Is something i coded when i started
using APE a while ago. It might even serve useful to your porpose.

Sent from my iPhone

> --
> You received this message because you are subscribed to the Google
> Groups "APE Project" group.
> To post to this group, send email to ape-p...@googlegroups.com
> To unsubscribe from this group, send email to
> ape-project...@googlegroups.com
> 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/

Micael Ribeiros

unread,
Apr 5, 2012, 10:02:43 AM4/5/12
to APE Project
Thank you for your fast response, I could use any kind of help. If you
didnt quite understand what Im asking Im going to try to resume it:

I dont want to have to create a 'global' channel on ape or have
clients connected to it, I just want to use a simple server-client
pipe. What Ive done so far is getting a user to connect the server,
send a command to the user but after that Im stuck, I cant get the
private 'client-server' pipe anywhere on the client (to send commands
to the server) and I cant get the user to join a channel (I get a 001
bad params error).

If you could give me some pointers on where to head to It would be
much appreciated.

Regards

On Apr 5, 3:52 pm, Pablo Tejada <ptejad...@gmail.com> wrote:
> I have an example and some code i would like to share with you but is
> sitting on my desktop at home. Is something i coded when i started
> using APE a while ago. It might even serve useful to your porpose.
>
> Sent from my iPhone
>

Micael Ribeiros

unread,
Apr 5, 2012, 10:06:16 AM4/5/12
to APE Project
A fast and simple solution that I can figure out is to set a dynamic
'channel' option on the Ape Client on each client (using the php
session id for example) but Im not sure if thats the correct way to do
it, I could end up with an extra channel/pipe that wouldnt be
necessary.

Pablo Tejada

unread,
Apr 5, 2012, 10:10:17 AM4/5/12
to ape-p...@googlegroups.com
And what exactly do you mean by private 'client-server' pipe?

To my understanding you want to have multiple chats in one page, is
that correct?

Sent from my iPhone

Micael Ribeiros

unread,
Apr 5, 2012, 10:22:15 AM4/5/12
to APE Project
Yes, but my doubts come before that. Lets imagine that a user opens
the website and does not join any channel, I still want to be able to
communicate 'privately' between the user and the server. For example
to change the nickname, retrieve the channels list, etc.. I want to do
this because I want the website to be as light as possible. Without
receiving large useless data from all the channels or all the users or
the ape server.

Regards

On Apr 5, 4:10 pm, Pablo Tejada <ptejad...@gmail.com> wrote:
> And what exactly do you mean by private 'client-server' pipe?
>
> To my understanding you want to have multiple chats in one page, is
> that correct?
>
> Sent from my iPhone
>

Louis Charette

unread,
Apr 5, 2012, 10:25:57 AM4/5/12
to ape-p...@googlegroups.com
If I understand correctly, you want the client to talk only to the ape server and not everybody else connected to APE?

In that case, defining a unique channel for each client could be an idea, but you still can use this global channel you're talking about, depending what command you are using. If you have a custom server-side command, you can sed the reply only to the client sending the command and not the entire channel.

But please tell us more about what you wan to do exactly, it may help us help you!


- Louis

Envoyé de mon iPhone

Micael Ribeiros

unread,
Apr 5, 2012, 10:57:45 AM4/5/12
to APE Project
Does a pipe get created when a user connects to the APE Server? If it
does and if I use a 'private' channel I would be creating another
pipe, so 2 pipes would be created for each user. I want to avoid doing
that and just use the first pipe that was created, but I cant seem to
'pass' that pipe to the user, and using for example "this.core.join"
on the client throws me error 001.

The second option that you mentioned, using a 'global' pipe/channel to
send messages between the server and the client seems to be the best
alternative to what Im trying to achieve, but still each user would be
connected to two pipes. Or am I wrong? Im actually not quite sure how
APE's pipes work but from what I could understand if the user connects
a pipe gets created, and I REALLY want to use just that pipe before
putting the user on others channels.

Regards

Louis Charette

unread,
Apr 5, 2012, 11:09:42 AM4/5/12
to ape-p...@googlegroups.com
I'll need to look at my code, but As far as I can remember, whatever method you use, you'll still be connected to only one pipe per channel you join.


- Louis

Envoyé de mon iPhone

Pablo Tejada

unread,
Apr 5, 2012, 11:35:05 AM4/5/12
to ape-p...@googlegroups.com
I think you should keep on coding and worry about performance
optimization later.

When a user is connected to the APE server, or any comet server, it is
given an identifier also know as the pubid or publisher id. This pubid
is essentially the index/name of the user object/pipe. Regardeless of
how many channels a user joins it will use the same pubid.

You can look at a pipe as a two way tunnel for reciving and sending
messages to the server. So you can recieve and send data throught the
user object/pipe without been in a chnnel.

A channel is just a goup of pipes, that is why is reffered as an multipipe.

Now, my suggestion to you is to have all users join a channel that you
could use to broadcast messages and for private communication with
specific users use their user pipes


Sent from my iPhone

Micael Ribeiros

unread,
Apr 5, 2012, 1:41:19 PM4/5/12
to APE Project
Thank you all for the help and information.

Ill try to solve my problem with identifying the user pipe on the
client and/or how to send the messages to the server on that pipe and
get back to you.

Regards

On Apr 5, 5:35 pm, Pablo Tejada <ptejad...@gmail.com> wrote:
> I think you should keep on coding and worry about performance
> optimization later.
>
> When a user is connected to the APE server, or any comet server, it is
> given an identifier also know as the pubid or publisher id. This pubid
> is essentially the index/name of the user object/pipe. Regardeless of
> how many channels a user joins it will use the same pubid.
>
> You can look at a pipe as a two way tunnel for reciving and sending
> messages to the server. So you can recieve and send data throught the
> user object/pipe without been in a chnnel.
>
> A channel is just a goup of pipes, that is why is reffered as an multipipe.
>
> Now, my suggestion to you is to have all users join a channel that you
> could use to broadcast messages and for private communication with
> specific users use their user pipes
>
> Sent from my iPhone
>

Pablo Tejada

unread,
Apr 5, 2012, 1:55:55 PM4/5/12
to ape-p...@googlegroups.com
Check this out
http://www.ape-project.org/docs/client/core/user.html

Just make sure to check for the core.user property from a ready event

Sent from my iPhone

Micael Ribeiros

unread,
Apr 6, 2012, 5:25:27 AM4/6/12
to APE Project
Thank you for the info Pablo Tejada.

Ive followed up on what you guys said but I still cant get my user
pipe.

On a 'ready' event on the client I dont even have a 'ape.core.user', I
do have a 'ape.core.users' but the pipe isnt there either.
On a 'raw' returned from the server I do have 'ape.core.user', but
still without a pipe, I do have a 'ape.core.user.pipes' but it seems
to be empty: ape.core.user.toSource() returns:
({casttype:"uni", pubid:"7ff9cce7030e0aa0237de7fdea2228f0", properties:
{pubid:"6528966ec91a721b9c861bc32e02e77b",
sid:"b82tq41f36gpbekcte7bl48hd5", uid:""}, pipes:{}})
(dont mind the 'sid', its the user php session id, I need it to detect
the user session on another application)

Can I get the user pipe from the pubid, if yes, how?

Regards,

On Apr 5, 7:55 pm, Pablo Tejada <ptejad...@gmail.com> wrote:
> Check this outhttp://www.ape-project.org/docs/client/core/user.html
>
> Just make sure to check for the core.user property from a ready event
>
> Sent from my iPhone
>

Micael Ribeiros

unread,
Apr 6, 2012, 5:34:31 AM4/6/12
to APE Project
I've also tried:
var pipe = this.core.getPipe(this.core.user.properties.pubid);
but 'pipe' is null

Micael Ribeiros

unread,
Apr 6, 2012, 5:36:58 AM4/6/12
to APE Project
Another weird thing is that on my 'rawClientready' Im supposed to get
a 'pipe' from the server:

this.onRaw('clientready', this.rawClientready);
rawClientready: function(params, pipe){ }

but it says that 'pipe' is undefined

Micael Ribeiros

unread,
Apr 6, 2012, 5:44:19 AM4/6/12
to APE Project
I've also tried to pass the pipe to the client on the server raw
'rawClientready', but when I try to use 'params.data.userpipe.send()'
I get 'params.data.userpipe.send' is not a function.

params.data.toSource() output: ({userpipe:0})

Micael Ribeiros

unread,
Apr 6, 2012, 5:55:56 AM4/6/12
to APE Project
More useful information for you guys to help me out:
This events are never fired: 'uniPipeCreate', 'multiPipeCreate',
'userJoin', 'pipeCreate'
So Im guessing I need to do something to 'create' that user pipe,
either on server or on the client

Louis Charette

unread,
Apr 6, 2012, 1:34:21 PM4/6/12
to ape-p...@googlegroups.com
Arg, I can't access the Ape Doc website again...

If you join a channel, a multipipe event should be fired. The Userjoin event is when a new user join the channel. This applied to yourself and you'll receive one "userjoin" event for each user already in a channel when you get in this channel. I don't remember what

Show us your code, it may help.

Envoyé de mon iPhone

Louis Charette

unread,
Apr 6, 2012, 1:37:38 PM4/6/12
to ape-p...@googlegroups.com
(damn, hit the send button by mistake)

I don't remember when the uniPipeCreate event is fired... And I can't access the doc website right now...

Show us your code, it may help.

Envoyé de mon iPhone

Micael Ribeiros

unread,
Apr 6, 2012, 3:07:09 PM4/6/12
to APE Project
Ok, finally I've solved my problem. I had the server set to restore
(set the user pubid to the old one) if the user was already connected
(page refresh for example) and that was preventing the user to get his
"old pipe" or even a "new pipe" to send data to the server:


clientConnect: function(params, cmd) {
Ape.log("User connecting... "+cmd.toSource());
if (!$defined(params) || !$defined(params.uid)) return 0;
if (params.uid.length > 16 || params.uid.test('[^0-9]', 'i'))
return ["006", "BAD_NICK"];
var tuid = params.uid;
cmd.user.setProperty('uid', params.uid); //the userid on the mysql
db
cmd.user.setProperty('sid', params.sid); //php session id
Ape.log("User connected with pubid: "+cmd.user.getProperty('pubid')
+" and sessionid: "+cmd.user.getProperty('sid'));
if (this.userslist.has(tuid)) {
//I removed it to solve the problem
//Ape.log("User already connected, setting his pubid to:
"+this.userslist.get(tuid));
//cmd.user.setProperty('pubid', this.userslist.get(tuid));
//tpubid = this.userslist.get(tuid);
}
this.userslist.set(tuid, cmd.user.getProperty('pubid'));
if(this.updateUser(cmd.user, params)){
params.pipe = {pubid:params.pipe}
}
// retrieve the username from the database
this.getUsername(tuid, function(nresult) {
cmd.user.setProperty('username', nresult);
cmd.user.username = nresult;
cmd.user.connected = true;
cmd.user.pipe.sendRaw('clientready', {pubid:tpubid});
}.bind(this));
return 1;
},

I still have a question to ask but Ill also open a new topic for
anyone that might know the answer. Im wondering in which ways would it
be better to restore a user's session on APE in terms of doing a multi-
channel/private chat. (IRC like), for example, would it fire the
userjoin event again on all users connected or not.

Thank you for your help Pablo and Louis.
Regards

waldo22

unread,
Jun 29, 2012, 12:45:25 AM6/29/12
to ape-p...@googlegroups.com
Micael,

I think this is exactly my problem.

Can you tell me what file you edited this in?  I can't seem to find it anywhere.

Thanks,

-Wes
Reply all
Reply to author
Forward
0 new messages