asfman
android developer
posts - 90,  comments - 213,  trackbacks - 0
package {
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.IOErrorEvent;
    import flash.events.ProgressEvent;
    import flash.external.ExternalInterface;
    import flash.net.Socket;
    public class receiveData extends Sprite
    {
        public function receiveData()
        {
           trace(ProgressEvent.SOCKET_DATA);
           socket.connect("127.0.0.1", 4300);
           socket.addEventListener(ProgressEvent.SOCKET_DATA, onServerData,false,0,true);
           socket.addEventListener(Event.CONNECT, connectHandler);
           socket.addEventListener(Event.CLOSE, closeHandler);
           socket.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
        }
        private var socket:Socket=new Socket();
        private var msg:String = "";
        private function onServerData(event:ProgressEvent):void{
            if(socket.bytesAvailable){
                msg = socket.readUTFBytes(socket.bytesAvailable);
                trace(msg);
                ExternalInterface.call("window.jsFunc", msg);
            }
        }
        private function connectHandler(event:Event):void{
           trace("connected");
        }
        private function closeHandler(event:Event):void{
           trace("closed");
            clearHandler();
        }
        private function ioErrorHandler(event:IOErrorEvent):void{
           //to do
           clearHandler();
        }
        private function clearHandler():void{
            socket.removeEventListener(ProgressEvent.SOCKET_DATA, connectHandler);
            socket.removeEventListener(Event.CONNECT, connectHandler);
            socket.removeEventListener(Event.CLOSE, closeHandler);
            socket.removeEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
        }
    }
}
posted on 2009-08-18 22:28 汪杰 阅读(545) 评论(0)  编辑 收藏 引用 所属分类: as3
只有注册用户登录后才能发表评论。

<2018年11月>
28293031123
45678910
11121314151617
18192021222324
2526272829301
2345678

常用链接

留言簿(15)

随笔分类(1)

随笔档案(90)

文章分类(727)

文章档案(712)

相册

收藏夹

http://blog.csdn.net/prodigynonsense

友情链接

最新随笔

搜索

  •  

积分与排名

  • 积分 - 380305
  • 排名 - 6

最新随笔

最新评论

阅读排行榜

评论排行榜