Hi,
I am having a lot of trouble finding out how the readUTFBytes function works. I am using the variable “socket” for the socket server that the flash client connects to.
I use the syntax “socket.write (string);” to write a string to the socket server and it works because I can see the string on the server side when I execute the swf.
I am very new to socket functions so I am using bits and pieces from multiple tutorials that I found online. None of them had nicely commented code :S.
I believe I need to use the following syntax to receive the server’s response as a string but I believe that no value is returned to the flash file:
//Event listener for when the socket server sends data to the client.
socket.addEventListener(ProgressEvent.SOCKET_DATA, onResponse);
//Function which is executed when data is sent to the client file.
function onResponse(e:ProgressEvent):void {
if (socket.bytesAvailable>0) {
trace (socket.readUTFBytes(socket.bytesAvailable)); //Not sure why I need this!
var box:String = socket.readUTFBytes(socket.bytesAvailable);
txt.text= String (box);//The display box's instance is "txt".
}
}
I managed to find out that the function above does not get executed because when I change the value of the text box string to something that’s not a variable (in quotes), it still does not display an output.
I am simply asking, "What is a simple way for me to do what should look something like “socket.read”(but of course that does not work)?
PLEASE HELP!