Groups | Blog | Home
all groups > flash actionscript > may 2004 >

flash actionscript : XMLSocket question



crazygamer
5/22/2004 5:13:30 PM
I'm creating a new socket, connecting to it and recieving a message from it
(all with success), but when i try socket.send, nothing happens. The socket
server is set up to send back whatever I send it, and since I've already
recieved stuff from it, i know the problem is with the sending. Does anyone
know what could be wrong with the socket.send . In the code, messages is a
textarea. Code attached.


//socket code
_global.socket = new XMLSocket();
socket.onConnect = function(success) {
if(!success) {
messages.text = "Unable to connect to server";
}
}
socket.onClose = function() {
messages.text += "Socket Closed";
}
socket.onXML = function(doc) {
displayRecieved(doc);
}
socket.onData = function(doc) {
displayRecieved(doc);
}
if(socket.connect("www.norcalmusic.net", 5555)) {
socket.send("<?xml version=\"1.0\"?><msg message=\"happyness\" />");
}
//
//buttons
send.addEventListener("click", submit);
reset.addEventListener("click", resetConn);
//listeners
_root.onKeyDown = function() {
if (Key.getCode() == Key.ENTER) {
if (input.text != "") {
submit();
}
}
}
//functions
function submit() {
/*tosend = input.text;
socket.send(tosend);
input.text = "";*/
socket.send("<?xml version=\"1.0\"?><msg message=\"happyness\" />");
}
function resetConn() {
socket.close();
socket.connect("www.norcalmusic.net", 5555);
}
function displayRecieved(doc) {
var xmlData = new XML(doc);
var node = xmlData.firstChild.nodeName;
var atts = xmlData.firstChild.attributes;
if(node == "welcome") {
messages.text += atts.toprint;
}
else if(node == "msg") {
messages.text += "\n"+atts.from+": "+atts.message;
}
messages.vPosition = messages.maxVPosition;
}
crazygamer
5/23/2004 4:46:35 PM
Jan-Paul K.
5/24/2004 9:04:26 AM
Hi,
I didn't do any xmlsocket things before, but maybe you should try sending an
xml object to the send function, since it awaits an object not a string
(actually a string should work as well, but you never know):

myXMLSocket .send( object )

"converts the XML object or data specified in the object parameter to a string
and transmits it to the server, followed by a zero byte." so maybe if you want
to send plain text, you need to attach a zero byte at the end of the string.

and maybe this part is somehow usefull as well:
"If the myXMLSocket object is not connected to the server (using
XMLSocket.connect ), the XMLSocket.send operation will fail. "

regards,
Paul

perry
5/24/2004 11:04:22 AM
socket.send("<?xml version=\"1.0\"?><msg message=\"happyness\" />" +
"\0");
don´t forget the null byte

perry


"crazygamer" <webforumsuser@macromedia.com> schrieb im Newsbeitrag
news:c8o1nq$gfn$1@forums.macromedia.com...
[quoted text, click to view]

AddThis Social Bookmark Button