Groups | Blog | Home
all groups > flash data integration > january 2005 >

flash data integration : How to receive Struct from VC++?


fardreamer
1/6/2005 9:33:38 AM
Hi, I'm trying to send a data structure such as

struct packet
{
int a;
int b;
int c;
};
(where a = 99, b = 2, c = 3 for example)

from a Visual C++ MFC Application (using CSocket) to a Flash movie using the
following code:

First, I declared a class as follows:

class Packet {
var a:Number;
var b:Number;
var c:Number;

// Constructor function
function Packet (a:Number, b:Number, c:Number) {
this.a = a;
this.b = b;
this.c = c;
}
}

I am able to connect to the VC++ Server succesfully and receive data using the
following code:

XMLSocket.prototype.onData = function(msg: Packet)
{
trace(msg);
}

However, instead of receiving the packet i send from the server, Flash MX
receives the character "c" followed by 2 lines of whitespace.

Can anyone help? I don't understand what i'm doing wrong here. Or are there
alternate methods for server-client communication?? (I am able to connect to
the server and send/receive Strings without any problems)
Stephen Beattie
1/6/2005 11:30:47 AM
I don't think you can do this without using some kind of serialization.
Actionscript cannot natively interpret C++ structs. Try serializing this
data as XML and have Actionscript instantiate a matching class in the Flash
movie based on the XML packet recieved.

You could use something like this perhaps:

<obj class="Packet">
<int id="a">1</int>
<int id="b">2</int>
<int id="c">3</int>
</obj>

You can then write actionscript to parse the XML and use the data to create
your instance on the flash side.

Alternatively, you could use a more compact string serialization technigue
that would give you somthing like:

Packet-i:a:1|i:b:2|i:c:3

1. split on '-' to get your className and grouped property data as an
array
2. split grouped property data on '|' to get your individual property
data as an array
3. split each property data on ':' to get an array [ propType, propName,
propValue ]

Sounds like what you're trying to acheive here is asynchronous flash
remoting. Now if you can find a way of sending/receiving AMF data over
XMLSockets let me know!!

Hope this helps

Stephen


[quoted text, click to view]

AddThis Social Bookmark Button