PDA

View Full Version : Probelm receive xml with XMLSocket


songchuan
02-02-2007, 06:26 AM
Hi! I'm doing a socket program which will send and receive data from a server. The server runs perfectly fine with other socket client (vb, java etc).

But I have problem receive data using XMLSocket in Flash. It send successfully, skip the receiving data and then finally go to "history" frame. See code below! Thanks!


var ip:String = "192.168.1.166";
var portNo:Number = 12111;
var client:XMLSocket = new XMLSocket();

client.onConnect = onSckConnect;
client.onData = onSckReceive;
client.onClose = function() {
trace("Connection to server lost.");
};

function onSckConnect(success:Boolean) {
if (success) {
trace("Connected to server!!");
} else {
traceAlert("Error connecting to server");
}
}

function onSckReceive(msg:String) {
traceAlert("Receiving: " + msg);
var doc:XML = new XML(msg);
}

if (client.connect(ip, portNo) == false) {
trace("Unsuccessful connection to server");
gotoAndStop("unsuccessful");
} else {
trace("Successfully connected to server");
client.send("<findmrn ip=\"192.168.1.99\"/>"+newline);
}
/*
client.onXML= function(xmlData){
trace("hello");
trace(xmlData.firstChild.firstChild.firstChild.nod eValue);
}*/

function traceAlert( msg:String ){
Alert.show( msg, "Error/Info", Alert.OK );
}

gotoAndStop("history");