jWebSocket Forum

[Search] Search   [Recent Topics] Recent Topics   [Hottest Topics] Hottest Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
put Object or ArrayList into a Token  XML
Forum Index » Communication Models, Events, Channels, Tokens
Author Message
dromani

jWebSocket Forum Fan
[Avatar]

Joined: 14/02/2011 19:00:26
Messages: 72
Location: Spain
Offline

Can I put an object or list of objects inside a token? Any problem if myObject is null or myObjectsArrayList is empty?

Thanks.
[WWW] [MSN]
aschulze

jWebSocket Owner
[Avatar]

Joined: 16/03/2010 18:15:55
Messages: 375
Location: Germany, Herzogenrath
Offline

Hi dromani,

to pass an arbitary object the object needs to implement the ITokenizable Interface to be serialized at the sender and deserialized at the target.

Then you can send it like this:

or

to send a arbitary "sub-token" within a token.
You can simply pass lists or maps by using the

methods.
To put an array into a token you can simply use:


Hope that helped.

Regards
Alex

This message was edited 1 time. Last update was at 21/02/2011 19:41:23

[WWW]
dromani

jWebSocket Forum Fan
[Avatar]

Joined: 14/02/2011 19:00:26
Messages: 72
Location: Spain
Offline

Very useful !

Thank you very much.
[WWW] [MSN]
dromani

jWebSocket Forum Fan
[Avatar]

Joined: 14/02/2011 19:00:26
Messages: 72
Location: Spain
Offline

ITokenizable cannot be resolved to a type. Which import needs?
[WWW] [MSN]
Kiwi

jWebSocket Forum User

Joined: 18/01/2011 18:09:32
Messages: 16
Offline

That import should be as following:



@Alex:

if I want to use Objects in a Map or in a List with



the Objects would obviously also require to implement the ITokenizable interface right?
dromani

jWebSocket Forum Fan
[Avatar]

Joined: 14/02/2011 19:00:26
Messages: 72
Location: Spain
Offline

Kiwi wrote:That import should be as following:



Thank Kiwi but it doesn't works, actually I don't have any org.jwebsocket.token package... I have jWebSocketServer-0.10.jar into my Eclipse referenced project libraries.

Can you help me, please?
[WWW] [MSN]
Kiwi

jWebSocket Forum User

Joined: 18/01/2011 18:09:32
Messages: 16
Offline

Dromani,

do you have also referenced jWebSocketCommon-0.11.jar??
The required class is in this jar.

If you want to develop a PlugIn I highly recommend Purans blogpost:

http://blog.jwebsocket.org/2010/10/16/jwebsocket-server-side-plugin-using-eclipse/


Cheers,

Kiwi
dromani

jWebSocket Forum Fan
[Avatar]

Joined: 14/02/2011 19:00:26
Messages: 72
Location: Spain
Offline

Kiwi wrote:
do you have also referenced jWebSocketCommon-0.11.jar??


No. I have installed latest version 0.10.0818. Where is the WebSocketCommon-0.11.jar? Inside latest build 1.0a6?
[WWW] [MSN]
Kiwi

jWebSocket Forum User

Joined: 18/01/2011 18:09:32
Messages: 16
Offline

Are you using the source or the binaries??

Using the source hast never worked for me properly.
Using the binaries there should be jWebSocketCommon-0.11.jar in the libs folder.
dromani

jWebSocket Forum Fan
[Avatar]

Joined: 14/02/2011 19:00:26
Messages: 72
Location: Spain
Offline

Kiwi wrote:Are you using the source or the binaries??


I'm using binaries. I found jWebSocketCommon-0.10 inside lib directory. Now, I'm trying jWebSocket v1.0a6 jars from Nightly Builds but I'm afraid because I need for a production environment...
[WWW] [MSN]
Kiwi

jWebSocket Forum User

Joined: 18/01/2011 18:09:32
Messages: 16
Offline

I can't really say anything about stability of that build sorry. I am not using it yet...Maybe someone of the jWebSocket team has more info on this...
aschulze

jWebSocket Owner
[Avatar]

Joined: 16/03/2010 18:15:55
Messages: 375
Location: Germany, Herzogenrath
Offline

Hi Guys,

we always strive to keep our API's upward compatible and since we already successfully ran a lot of tests we encourage you to update to 1.0, even if it is still alpha, to benefit from the latest improvements and extensions.
Please consider that 0.10 is not a production version as well and that the WebSocket protocol might still be subject to changes until the final specification (not because of us but due to updates by the W3C or the IETF).
For the case you plan to update to 1.0aX, please ensure that all libraries always are from the same package. Don't mix various versions in a single installation.

Best Regards
Alex

This message was edited 2 times. Last update was at 20/03/2011 20:40:38

[WWW]
dromani

jWebSocket Forum Fan
[Avatar]

Joined: 14/02/2011 19:00:26
Messages: 72
Location: Spain
Offline

Thanks Alex.
[WWW] [MSN]
dromani

jWebSocket Forum Fan
[Avatar]

Joined: 14/02/2011 19:00:26
Messages: 72
Location: Spain
Offline

Ok. I have a new question.

Now I can put an object (which implements itokenizble) into a token and send to JS client-side. Everything works fine and I got a JS object well, but I need to send a list of objects (same class) to client-side into one token.

Server code:
List<myClass*> myObjects = new ArrayList<myClass>();
myObjects.add(new myClass("1", 1, "one"));
myObjects.add(new myClass("2", 2, "two"));
myObjects.add(new myClass("3", 3, "three"));
tokenResponse.setList("myList", myObjects);
*(obviously, myClass implements ITokenizable with writeToToken method)

Client code:
var myObjects = [];
myObjects = responseToken.myList

myObjects get an array of strings with all atributtes of each object in plain text and I need an array of objects. How can I do? Thank you.
[WWW] [MSN]
kyberneees

jWebSocket Committer
[Avatar]

Joined: 10/10/2010 23:13:03
Messages: 96
Offline

Hi dromani,
The question is that ITokenizable interface is processed only in the first level, not recursive.

About abstract types (strings, integer, double, list, etc...) is for cross compatibility.
So, how you can do that? The answer is "for nested objects use Tokens".

Server code:
List<myClass*> myObjects = new ArrayList<myClass>();
myObjects.add(token1);
myObjects.add(token2);
myObjects.add(token3);
tokenResponse.setList("myList", myObjects);

*(obviously, tokenN are instances of Token. Use: TokenFactory.createToken)

Be open for more questions or suggestions.

Best Regards,
Rolando





Ing. Rolando Santamaría Masó
Email: rsantamaria@jwebsocket.org
Twitter: https://twitter.com/kyberneees
[WWW]
 
Forum Index » Communication Models, Events, Channels, Tokens
Go to:   
Powered by JForum 2.1.9 © JForum Team