[Clug-tech] JavaScript objects and inheritance

John Jardine john_e_jardine at spamcop.net
Wed Sep 3 10:12:36 PDT 2008


I was wondering if there is an easy way to this...
I am sending messages between a server and a flash file running in a
browser.

The browser is using a Java applet to send/receive the data because it's
UDP based.  The messages all start out the same (header info) but differ
16 bytes in, based on the type of data they'll carry. I'd like to be
able to do it via a somewhat generic object.

So to summarize the current data flow:
Internet UDP packets <=> Java <=> JavaScript <=> ActionScript

In a perfect world I'd like to have ActionScript send/rcv UDP
packets ... but it's not a perfect world.  This has led me to the
current method.  Now I'm trying to make the client message handling more
generic and a little less fragile.

What I'd like to end up with is a generic Java message:
public class myMessage {
public int msg_version;
public int msg_userid;
public int msg_session;
public int msg_class;
public int msg_type;
.
.
.
Then extend this generic class with more specific message types:
public class myLoginMessage extends myMessage {
public int msg_version;
public int msg_userid;
public int msg_session;
public int msg_class;
public int msg_type;
public String login_name;
public String password;
.
.
.

Then as these message types arrive, I have Java call JavaScript which
retrieves the message and passes it on to ActionScript.

Is there a way to do this or am I stuck creating different objects for
each message type?

Any insight's would be welcome.  I already have something working - I
just don't like it and am looking for something better.

Another thing... the whole communications design is to off-load the
server as much as possible.  I don't care how hard or convoluted the
client side gets as long as I can keep my server side ridiculously
simple (and blazingly fast).




More information about the clug-tech mailing list