2009-01-16

FLEX AS3 使用 SOCKET 連接 POP3

範例檔如下

但是~

還不知道讀回來的資料要怎麼處理 @@ 頭痛~~


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

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical" fontSize="12">

<mx:Script>

<![CDATA[

public var mysocket:Socket = null;



private function startConnect():void{

this.mysocket = new Socket("pop3.mail2000.com.tw",110);

this.mysocket.addEventListener(ProgressEvent.SOCKET_DATA,process);



}

private function endConnect():void{

this.mysocket.writeUTFBytes("quit\n");



this.mysocket.flush();

this.textArea.text = this.textArea.text +this.mysocket.readUTFBytes(this.mysocket.bytesAvailable);

}



private function process(event:ProgressEvent):void{

var tmpStat:String = this.mysocket.readUTFBytes(this.mysocket.bytesAvailable);



if(tmpStat.indexOf("+OK MPOP3 Server")!= -1){

mysocket.writeUTFBytes("user 帳號\n");

}

if(tmpStat.indexOf("+OK Password required")!= -1){

mysocket.writeUTFBytes("pass 密碼\n");

}



if(tmpStat.indexOf("+OK heydod has")!= -1){

mysocket.writeUTFBytes("retr 1\n");

}

this.textArea.text = this.textArea.text + tmpStat;

mysocket.flush();

}

]]>

</mx:Script>

<mx:TextArea width="100%" height="50%" id="textArea"/>

<mx:HBox width="100%" horizontalAlign="center">

<mx:Button label="連線" click="startConnect()"/>

<mx:Button label="斷線" click="endConnect()"/>

</mx:HBox>



</mx:Application>

沒有留言: