7 Replies Latest reply on Jul 20, 2011 8:43 AM by yyterrwihbgd

    Problem with socket responses with flex

    yyterrwihbgd Level 1

      Hi, I am using the code below to connect to an IMAP server.

      When I telnet to the server and use the commands that I am sending in the code, the rsponses are correct.


      However, when I run the code below, I only obtain the ready and logged in responses as shown below.


      Any ideas why I am not receiving the full set of responses from the socket?

      Thanks in advance fro your advice.


      The following is the output from the code:

      +++++++++++++++++ START SENDING IMAP DATA +++++++++++++++++++++++++

      sent: . login user1 myPassword

      sent: . status INBOX (messages)

      sent: . select INBOX

      +++++++++++++++++ END SENDING IMAP DATA +++++++++++++++++++++++++

      ++++++++ [IMAP START]

      Response is: * OK Dovecot ready.

      [IMAP END] +++++++++

      ++++++++ [IMAP START]

      Response is: . OK Logged in.

      [IMAP END] +++++++++



      The code is:


      <?xml version="1.0" encoding="utf-8"?>

      <s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"





      <!-- Place non-visual elements (e.g., services, value objects) here -->







      public var dataStr:String;

      private var socket:Socket;

      private var serverURL:String= "dead.org";

      private var serverPort:int = 143;

      private var serverResponse:ByteArray = new ByteArray();


      private function init():void


        this.serverURL = serverURL;

        this.serverPort = serverPort;

        socket = new Socket();

        socket.addEventListener(ProgressEvent.SOCKET_DATA,handleNewIMAPData); //Event when socket receives new data






      private function sendString(dataStr:String):void


        var bytes:ByteArray = new ByteArray();

        bytes.writeMultiByte(dataStr, "UTF-8");



        trace("sent: " + dataStr);



      public function sendIMAPdata():void


        trace("\t +++++++++++++++++ START SENDING IMAP DATA +++++++++++++++++++++++++");

        dataStr =". login user1 myPassword" + "\r\n";


        dataStr =". status INBOX (messages)" + "\r\n";


        dataStr =". select INBOX" + "\r\n";


        trace("\t +++++++++++++++++ END SENDING IMAP DATA +++++++++++++++++++++++++");



      private function handleNewIMAPData(event:ProgressEvent):void


        var numBytes:int = socket.bytesAvailable;

        serverResponse = new ByteArray();




          var byte:int = socket.readUnsignedByte();




        var response:String = serverResponse.toString();

        trace(" ++++++++ [IMAP START]\n Response is: " + response + "[IMAP END] +++++++++\n");



      private function connectToServer():void


        socket.connect(serverURL, serverPort);