如何使用NetStream请求?

时间:2016-11-18 03:35:45

标签: actionscript-3 netstream netconnection

在我使用NetConnection请求之前是正常的。现在我需要使用NetStream来请求。但我不知道如何使用它。 这是NetConnection代码。

`

        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();
        }
    }

`

此请求的作用相当于使用PING工具。现在我应该如何使用NetStream来实现请求,它是在两个IP延迟,抖动和丢包率之间的指定时间内测试的角色

0 个答案:

没有答案