Web Hosting Talk







View Full Version : Sending XML from VB to Flash


X-TechMedia
05-18-2003, 11:05 AM
Ive spent the last couple of days trying to figure this out!
I can send data from the flash movie to my VB program, but I cant seem to send data from VB to Flash!


Im sending data from VB using:
sckAccept(iClientId).SendData "<USER>Admin</USER><MESSAGE>gergreg</MESSAGE>"

And receiving it in Flash using:

var user = messageObj.firstChild.firstChild.nodeValue;
var message = messageObj.childNodes[1].firstChild.nodeValue;
incoming += user + " says:</B> " + message + "\n";

I get nothing show up on the output window either!
Any ideas?!

krumms
05-18-2003, 12:36 PM
I've not used ActionScript, so I'll have to guess - how are you accepting the incoming socket connection? (i.e. the one from VB to your Flash application) Your ActionScript code only seems to be dealing with the XML aspect of this problem, when I think it's more likely to be a socket problem.

X-TechMedia
05-18-2003, 12:37 PM
This is the code for the incoming data:

mySocket.onXML = handleIncoming;

function handleIncoming (messageObj) {

// display the received xml data in the output window
trace("--------new data received-----------");
trace(">>" + messageObj.toString() + "<<");
trace("-------- end of new data -----------");

var user = messageObj.firstChild.firstChild.nodeValue;
var message = messageObj.childNodes[0].firstChild.nodeValue;

// add the message to the chat window, with a time stamp
incoming += user + "says: " + message + "\n";
}

krumms
05-18-2003, 12:41 PM
*scratches head* this might be my misunderstanding of ActionScript, but I see nothing there actually accepting an incoming connection? Is mySocket a socket you have accepted using serverSocket.accept or something like that?

Sorry, really don't know actionscript at all, for all I know even accepting incoming connections might be event based :$

[edit:] ah, just noticed that VB was accepting the incoming connection - I thought Flash was acting as your server ;) Try fixing up the XML such that it has a root node.

krumms
05-18-2003, 12:45 PM
also worth noting, your XML is badly formed. You need a root element around the user and message elements, and you SHOULD also have the line '<?xml version="1.0" encoding="UTF-8"?>' in there too.

X-TechMedia
05-18-2003, 12:46 PM
In my connect function i hav the following:
function connect () {
mySocket = new XMLSocket();
mySocket.onConnect = handleConnect;
mySocket.onClose = handleClose;
mySocket.onXML = handleIncoming;

if (!mySocket.connect("localhost", 4500)) gotoAndStop("error");
mySocket.host = host;
mySocket.port = port;
}

so it should be waiting for connections.
Thanks for suggesting that though! Wouldnt of suprised me!

This has got me totally confused as well!

X-TechMedia
05-18-2003, 12:47 PM
root element?! :eek:

Whats one of those!
Ive never used XML before, but i figured I had to as Flash only has XMLSockets!

krumms
05-18-2003, 12:49 PM
<event> <!-- this is your root element! -->
<user>bob</user> <!-- a child element -->
<message>Wassup?</message> <!-- another child element -->
</event>

;) see if that helps

X-TechMedia
05-18-2003, 12:55 PM
Hmmm......still no joy.
I think it might be somthing to do with the socket, as I dont even get it to write to the output window using

trace("--------new data received-----------");
trace(">>" + messageObj.toString() + "<<");
trace("-------- end of new data -----------");

krumms
05-18-2003, 12:58 PM
hmm ... if I wasn't so tired I'd do a bit more poking around, but I'm installing bugzilla then going to bed ;) sorry matey - if you still haven't resolved it when I next visit I'll have a look around, although I imagine with the many brilliant minds here it'll be sorted out by then :)

X-TechMedia
05-18-2003, 01:01 PM
Well at least I know what a root element is know! ;)
Thanks!

Im determined to get this working, but I think its time to go home as well, at work on a sunday just isnt right!:stickout:

X-TechMedia
05-19-2003, 06:04 AM
All sorted!!
Turns out all i needed to do was put a null character at the start and end of the string I was sending!! (VBNullChar)

krumms
05-19-2003, 08:19 AM
:S that's weird as