jeudi 17 novembre 2016

【AS3】How to use NetStream to request?

Before I use NetConnection to request is normal.now I need to use NetStream to request. but I do not know how to use it。 This is NetConnection code.

`

        public function start():void 
            {
                uploadtime = KService.ContextService.configure.uploadtime[0];
                downloadtime = KService.ContextService.configure.downloadtime[0];
                jittertime = KService.ContextService.configure.jittertime[0];
                totaltime = uploadtime + downloadtime + jittertime;

                checkPercent();

                for(var i:int;i<512;i++)
                {
                    upsendStr+="1";
                }

    //          var url:String = CheckInit.server;//KService.ContextService.configure.server[0].@url;
                var url:String = "rtmfp://10.27.11.51/MonaStatus/";//10.27.11.51 is fake
                if (_conn)
                    _conn.close();
                _conn = new NetConnection();
                _conn.addEventListener(NetStatusEvent.NET_STATUS, onStatus);
                _conn.connect(url);
                _conn.client = this;

                var stream_ns:NetStream = new NetStream(_conn);
                stream_ns.dataReliable = false;
    //          stream_ns.play("MyVideo");
    ////            vid.attachNetStream(stream_ns);
    //          stream_ns.client = stream_ns;
    //          stream_ns.send("myFunction", "hello");
            }

            private function onStatus(event:NetStatusEvent):void 
            {
                trace(event.info.code);
                switch(event.info.code) {
                    case "NetConnection.Connect.Success":
                    {   
                        show("正在测试中,请耐心等待...");

                        btnStart.enabled = false;

                        checkUploadSpeed();
                    //  checkDownLoadSpeed();
                    //  checkLostAndLatency
                    //  checkJitter();

                        break;
                    }
                    case "NetConnection.Connect.Closed":
                    {   
                        connectionFailed();

                        break;
                    }
                    case "NetConnection.Connect.Failed":
                    {   
                        connectionFailed();
                        break;
                    }
                    default:
                    {

                    }
                }
            }
private function checkUploadSpeed():void
        {
            upSpeed = 0;
            show("正在测试上传速度...");
            setTimeout(stopUploadData,uploadtime);

            uid = UIDUtil.createUID();

            var processcount:Number =    Number(KService.ContextService.configure.processcount[0]);

        for(var i:int;i<processcount;i++)
        {
            var upcheck:UploadCheck = new UploadCheck();
            upcheck.uid = uid;
            upcheck.start();
        }
    }

`

The role of this request is equivalent to use PING tools. Now I should how to use the NetStream to achieve the request, it is the role of testing within the specified time between the two IP delay, jitter and packet loss rate

Aucun commentaire:

Enregistrer un commentaire