title: AS3 - Flash/AIR Socket Communication writeUTFBytes only works once
body: <p>I have a socket server listening on 2 ports, 1 port for the socket server and 1 port for the policy server.</p>
  
  <p>My code is below, in this scenario, data is sent and received perfectly fine. however, for example if I add a button with a simple:</p>
  
  <p><code>
      socket.writeUTFBytes("Message");
      socket.flush();
  </code></p>
  
  <p>after the initial connection, it doesn't seem to send any data to my server (I have my server printing all data transmissions to the console for checking) Initial connections work fine, as seen below:</p>
  
  <p><code>
      //authenticate with socket server first:
      var xmlSocket = new XMLSocket();
      xmlSocket.connect("192.xx.xx.xx", 843);</p>
  
  <pre><code>try {
      Security.loadPolicyFile("xmlsocket://192.xx.xx.xx:843");
  } catch (e:IOError) {
      //tbOutput.text += e.text;
  }
  
  
  var socket:Socket = new Socket();
  socket.addEventListener(Event.CONNECT, onConnect);
  socket.addEventListener(Event.CLOSE, onClose);
  socket.addEventListener(IOErrorEvent.IO_ERROR, onError);
  socket.addEventListener(ProgressEvent.SOCKET_DATA, onResponse);
  socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecError);
  
  try {
  socket.connect("192.xx.xx.xx", 4444);
  } catch (e:IOError) {
      //error traced
  }
  
  
  function onConnect(e:Event):void {
      //initial message to socket server:
      var Message:String;
      //message contains something
      socket.writeUTFBytes(Message.toString() + "&lt;EOF&gt;");
      socket.flush();
  
      }
  </code></pre>
  
  <p></code></p>