0

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

null
  • 5,207
  • 1
  • 19
  • 35
SunnyWu
  • 11
  • 2
  • 1
    `NetStream` just decodes a/v media so you will have to still use your `NetConnection` part again anyways. Since you have it working, why do you need NetStream? Is there something in the NetStream API you need? – VC.One Nov 18 '16 at 20:47
  • I am in the realization of an end to the end of the web speed tool (TCP velocity and UDP velocity measurement points), the tool is similar to the use of a web site PING. Before I used NetConnection to test out the data with the PING out of the data a little gap, after the data found that the use of NetConnection is on the transport layer, and PING is the underlying ICMP. I would now like to use UDP to implement the NetStream test. Access to FLASH official documents, found that there is a method called NetStream Send method, but I do not know whether the method can meet my needs. – SunnyWu Nov 21 '16 at 01:45
  • Servers is not my main area but... I don't think the NetStream `send` can be used for ping tests. For **TCP** you use [**`Socket`**](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/Socket.html) class. For **UDP** you use [**`Datagram Socket`**](http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/DatagramSocket.html) class. Also UDP can only be done via making an AIR app, you export as desktop app (eg: EXE) or as mobile app (eg: APK), but not as SWF. See this [**example**](http://blog.debit.nl/2010/06/mdns-daap-announce-air-2-0/) UDP code... – VC.One Nov 23 '16 at 03:22

0 Answers0