title: Unable read data from Socket
body: <p>I have a flash AS3 file which interacts with a socket server, server sends data as plain text. I am unable to read the data whats being send from the server using Socket class. Code what I am using in flash is below.</p>
  
  <pre><code>var socket:Socket = new Socket("localhost", 9231);
  
  socket.addEventListener(Event.CONNECT, socketConnectHandler, false, 0, true);
  socket.addEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler, false, 0, true);
  
  function socketConnectHandler(event:Event):void{
      trace("Connection has been established ");
  }
  
  function socketDataHandler(event:ProgressEvent):void{   
      var stream:ByteArray = new ByteArray();
      socket.writeBytes(stream, 0, 0);
      trace(stream.readUTF());
      trace( socket.readUTF());
  }
  </code></pre>
  
  <p>I get below error for while I try to read ByteArray and socket data being send.</p>
  
  <pre><code>Error: Error #2030: End of file was encountered.
      at flash.net::Socket/readUTF()
      at socket_test_fla::MainTimeline/socketDataHandler()
  </code></pre>
  
  <p>I have tried various combinations to get it working without success. Any clue to help me understand the issue and find a fix would be grateful.</p>
  
  <p>Update:</p>
  
  <p>I modified code given by @t to</p>
  
  <pre><code>var stream:ByteArray = new ByteArray();
  socket.writeBytes(stream, 0, 0);
  
  var data:String = "";
  while(socket.bytesAvailable &gt; 0) {
    data += socket.readByte();
  }
  
  trace("data "+ data);
  </code></pre>
  
  <p>I get trace as "0124661171161161111109579756184114117101124-1" or similar bunch of numbers. Any idea to convert these codes to respective characters?</p>