Sending data to only one user extension.

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

Post Reply
AlexanderTheGreat
Posts: 21
Joined: 20 Nov 2008, 22:18

Sending data to only one user extension.

Post by AlexanderTheGreat »

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...
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

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)
Lapo
--
gotoAndPlay()
...addicted to flash games
AlexanderTheGreat
Posts: 21
Joined: 20 Nov 2008, 22:18

Post by AlexanderTheGreat »

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 :|.
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

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 )
Lapo
--
gotoAndPlay()
...addicted to flash games
AlexanderTheGreat
Posts: 21
Joined: 20 Nov 2008, 22:18

Post by AlexanderTheGreat »

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.

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

Post by AlexanderTheGreat »

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.
samirn
Posts: 11
Joined: 09 Sep 2008, 23:56

Post by samirn »

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)
AlexanderTheGreat
Posts: 21
Joined: 20 Nov 2008, 22:18

Post by AlexanderTheGreat »

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.
orthiac
Posts: 115
Joined: 25 Jun 2008, 10:03
Location: Massachusetts, USA

Post by orthiac »

If param[0] is a <java.lang.String> and the name of a user logged into the Zone...
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)
- Mike
AlexanderTheGreat
Posts: 21
Joined: 20 Nov 2008, 22:18

Post by AlexanderTheGreat »

Thank you so much Orthiac/Mike the code works like a Charm. You have been a real help, you rock.

Thanks again :).
Post Reply