# XMLSockets readUTFBytes: Please help me

**URL:** <https://forum.kirupa.com/t/xmlsockets-readutfbytes-please-help-me/319102>\
**Category:** Uncategorized\
**Created:** [February 9, 2011, 2:16am UTC](https://forum.kirupa.com/t/xmlsockets-readutfbytes-please-help-me/319102 "2011-02-09T02:16:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Taloton](https://avatars.discourse-cdn.com/v4/letter/t/9d8465/32.png) [@Taloton](https://forum.kirupa.com/u/Taloton)\
**Post date:** [February 9, 2011, 2:16am UTC](https://forum.kirupa.com/t/xmlsockets-readutfbytes-please-help-me/319102/1 "2011-02-09T02:16:03Z")

</div>

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:

```auto

//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!
