Sending data to only one user extension.
-
AlexanderTheGreat
- Posts: 21
- Joined: 20 Nov 2008, 22:18
Sending data to only one user extension.
How would I send raw string data to a custom user. Like the way a private message system would work. This must be a java extension.
I have tried this code:
LinkedList person=new LinkedList();
person.add(params[0]);
sendResponse(res, fromRoom, u, person);
But no luck. The params[0] holds the username.
No luck...
I have tried this code:
LinkedList person=new LinkedList();
person.add(params[0]);
sendResponse(res, fromRoom, u, person);
But no luck. The params[0] holds the username.
No luck...
the LinkedList must contain SocketChannel objects (java.nio.channels.SocketChannel)
Code: Select all
LinkedList recipients = new LinkedList()
recipients.add( anyUserObject.getChannel() )
sendResponse(res, fromRoom, u, recipients)-
AlexanderTheGreat
- Posts: 21
- Joined: 20 Nov 2008, 22:18
Thank you lapo.
I have also had a problem creating a Channel Object. I googled it but it came out in file input and output. I also had a look at the PixelGame java sample. I found some code and customized it as it looks quite helpful.
I'm not sure how to create the channel object. Here's what I came out with.
SocketChannel uName = (SocketChannel) params[0];
LinkedList recipients = new LinkedList()
recipients.add( uName.getChannel() )
sendResponse(res, fromRoom, u, recipients)
No Luck
.
I have also had a problem creating a Channel Object. I googled it but it came out in file input and output. I also had a look at the PixelGame java sample. I found some code and customized it as it looks quite helpful.
I'm not sure how to create the channel object. Here's what I came out with.
SocketChannel uName = (SocketChannel) params[0];
LinkedList recipients = new LinkedList()
recipients.add( uName.getChannel() )
sendResponse(res, fromRoom, u, recipients)
No Luck
You don't need to create any channel.
Channels are created by the server when a client connects to the server, so you can simply call the User.getChannel() method when it is required by one of the API methods.
When you send messages to clients you simply provide a list of channels of already connected users ( the recipients of your message )
Channels are created by the server when a client connects to the server, so you can simply call the User.getChannel() method when it is required by one of the API methods.
When you send messages to clients you simply provide a list of channels of already connected users ( the recipients of your message )
-
AlexanderTheGreat
- Posts: 21
- Joined: 20 Nov 2008, 22:18
Ok, So how do I create the userobject? I don't want to send data to my user in the client, I want to send it to another user in the client like a PM.
I'm guessing this is the api call I use?
User person=new User(channel,params[0],currZone);
person.getChannel();
LinkedList recipients = new LinkedList()
recipients.add(person.getChannel() )
sendResponse(res, fromRoom, u, person)
No luck there too.
Sorry for me being so thick.
I'm guessing this is the api call I use?
User person=new User(channel,params[0],currZone);
person.getChannel();
LinkedList recipients = new LinkedList()
recipients.add(person.getChannel() )
sendResponse(res, fromRoom, u, person)
No luck there too.
Sorry for me being so thick.
Lapo wrote:You don't need to create any channel.
Channels are created by the server when a client connects to the server, so you can simply call the User.getChannel() method when it is required by one of the API methods.
When you send messages to clients you simply provide a list of channels of already connected users ( the recipients of your message )
-
AlexanderTheGreat
- Posts: 21
- Joined: 20 Nov 2008, 22:18
Sorry for the double post.
So your saying I need to send it to all the users in the room and then only allow the user with param that matches up with there username to recieve there message.
client code:
if(sfs.myUserName==param[0]){
trace("message...");
}
else{
//just skips this... since this is not for this user.
}
I'm really confused, lol.
So your saying I need to send it to all the users in the room and then only allow the user with param that matches up with there username to recieve there message.
client code:
if(sfs.myUserName==param[0]){
trace("message...");
}
else{
//just skips this... since this is not for this user.
}
I'm really confused, lol.
-
AlexanderTheGreat
- Posts: 21
- Joined: 20 Nov 2008, 22:18
samirn wrote:No, you can supply a list of recipient channels in sendResponse. So you should change your extension code to:
LinkedList recipients = new LinkedList()
recipients.add(person.getChannel() )
sendResponse(res, fromRoom, u, recipients)
As I said many times I don't know the recipients name im sending the data to so it will be in the param.
Tell me how to write param[0].getChannel();
I already know that other stuff.
If param[0] is a <java.lang.String> and the name of a user logged into the Zone...
Have you tried:
- Mike
Have you tried:
Code: Select all
User person = currZone.getUserByName(param[0])
LinkedList recipients = new LinkedList()
recipients.add(person.getChannel() )
sendResponse(res, fromRoom, u, recipients)-
AlexanderTheGreat
- Posts: 21
- Joined: 20 Nov 2008, 22:18