The relationship between Netconnection and NetStream in Flex, and the number of browser concurrent connections test [go]

Source: Internet
Author: User
Tags addchild

Recently in a BS-based video conferencing system, decided to use open source Fluorinefx.net and flex method to develop, early development is very smooth, including synchronous whiteboard. However, when the real-time video transmission, the original design is that each client can display three video, but to the test on IIS, the discovery State is very unstable, and occasionally can be fully displayed, in most cases, the client always randomly display one or two. The technical documentation of ActionScript, the technical documentation of FLUORINEFX, etc. were queried, and no description of the problem was found, including the correspondence between Netconnection and NetStream on the network, and there was no definite explanation or summary. The program is really looking for problems, I initially suspect that the browser concurrent connection limit problem caused by the inability to connect the multi-channel video in the browser's SWF, so decided to abstract this part, specifically to do a test, testing selected three more Representative browser.

Development environment: VS2008 (fluorinefx.net) and FlexBuilder3

Test environment: IE 8,CHROME,FF + Flash Player one-debug version

First, the Test Flow processing service program is written

First, a new Fluorineservice project was created with VS 2008 and the application adapter class was added to determine the legality of the connection when Rtmp was connected AppConnect, that is, only if the rtmp connection Parameters[1] is "000" Connection request is allowed to connect to the RTMP channel port on the server as follows:

Using FluorineFX;
Using FluorineFx.Messaging.Adapter;
Using FluorineFx.Messaging.Api;
Using FluorineFx.Messaging.Api.SO;

Namespace Onlineservice
{
public class Demoapp:applicationadapter
{

public override bool AppConnect (iconnection connection, object[] parameters)
{
String userName = Parameters[0] As String;
string password = parameters[1] As String;

Here you can customize the login judgment verification logic, here as long as the password is 000 to enter
if (Password! = "000")
return false;
return true;
}

}

}

After you create a new FluorineFX Web, modify the Services-config.xml document under its Web-inf/flex folder to specify the port used by the RTMP transport channel:

        <channel-definition id= "my-rtmp" class= "Mx.messaging.channels.RTMPChannel" >
<endpoint uri= "rtmp://{server.name}:2037" class= "Flex.messaging.endpoints.RTMPEndpoint"/>
<properties>
<idle-timeout-minutes>20</idle-timeout-minutes>
</properties>
</channel-definition>

Add the Apps folder under the FluorineFX Web project root directory, add the Onlineuser folder under Apps, Add the App. config profile and a streams folder under Onlineuser, streams down into five flv video files (I've collected a small piece of video from my own flex-writing program, and copied it into 5 parts under this folder, named Mytest1 ... )

The service program that specifies the stream processing in App. config is DemoApp, as follows:

<?xml version= "1.0" encoding= "Utf-8"?>
<configuration>
<application-handler type= "Onlineservice.demoapp"/>
</configuration>

Start debugging after compilation so that ASP. Development server is running (to provide streaming services)

Second, the development of testing Flex project
After opening flex Builder3, create a new Flex project, set the Flex directory under the root of the FLUORINEFX Web project established in "one", and introduce the relevant libs and compilation parameters as shown in:

Then write the Mxml file as follows:

<?xml version= "1.0" encoding= "Utf-8"?>
<mx:application xmlns:mx= "Http://www.adobe.com/2006/mxml" layout= "Absolute"

Backgroundgradientcolors= "[#000000, #049FF1]" fontsize= "initialize=" init () ">
<mx:hbox id= "HBox" x= "y=" to "width=" 1234 "height=" 187 ">
</mx:HBox>
<mx:script source= "fiveconnfivestream.as"/>
</mx:Application>

Add a fiveconnfivestream.as file under which five netconnection and five NetStream are connected, respectively, to the five video files in "One", as follows:

Import flash.events.NetStatusEvent;
Import flash.net.NetConnection;
Import Flash.net.NetStream;
Import Mx.controls.VideoDisplay;
Import Mx.messaging.config.ServerConfig;
private Var rtmpchanner:string;
private Var nc:netconnection;
private Var nc2:netconnection;
private Var nc3:netconnection;
private Var nc4:netconnection;
private Var nc5:netconnection;
private Var Ns1:netstream;
private Var Ns2:netstream;
private Var Ns3:netstream;
private Var Ns4:netstream;
private Var Ns5:netstream;

Private Function init (): void
{
Rtmpchanner=serverconfig.getchannel ("My-rtmp"). endpoint+ "/onlineuser";
Nc=new netconnection ();
Nc.addeventlistener (Netstatusevent.net_status,onconnhandler);
Nc.client=this;
Nc.connect (Rtmpchanner, "Adsfasdf", "000");

Nc2=new netconnection ();
Nc2.addeventlistener (NETSTATUSEVENT.NET_STATUS,ONCONNHANDLER2);
Nc2.client=this;
Nc2.connect (Rtmpchanner, "Adsfadasdf", "000");

Nc3=new netconnection ();
Nc3.addeventlistener (NETSTATUSEVENT.NET_STATUS,ONCONNHANDLER3);
Nc3.client=this;
Nc3.connect (Rtmpchanner, "Adsfffasdf", "000");

Nc4=new netconnection ();
Nc4.addeventlistener (NETSTATUSEVENT.NET_STATUS,ONCONNHANDLER4);
Nc4.client=this;
Nc4.connect (Rtmpchanner, "Adfgg", "000");

Nc5=new netconnection ();
Nc5.addeventlistener (NETSTATUSEVENT.NET_STATUS,ONCONNHANDLER5);
Nc5.client=this;
Nc5.connect (Rtmpchanner, "adfaaa", "000");
}

Private Function Onconnhandler (event:netstatusevent): void
{
Trace ("Connection One State:" +event.info.code);
if (event.info.code== "NetConnection.Connect.Success")
{
var vds:videodisplay=new videodisplay ();
vds.height=160;
vds.width=240;
var vd:video=new Video ();
vd.width=240;
vd.height=160;
This.ns1=new NetStream (THIS.NC);
This.ns1.addEventListener (Netstatusevent.net_status,onstreamhandler1);
Vd.attachnetstream (THIS.NS1);
This.ns1.client=this;
This.ns1.play ("Mytest1");
Vds.addchild (VD);
This.hbox.addChild (VDS);
Trace ("Play one");
}
}


Private Function OnConnHandler2 (event:netstatusevent): void
{
Trace ("Connection two status:" +event.info.code);
if (event.info.code== "NetConnection.Connect.Success")
{
var vds2:videodisplay=new videodisplay ();
vds2.height=160;
vds2.width=240;
var vd2:video=new Video ();
vd2.width=240;
vd2.height=160;
This.ns2=new NetStream (THIS.NC2);
This.ns2.addEventListener (NETSTATUSEVENT.NET_STATUS,ONSTREAMHANDLER2);
Vd2.attachnetstream (THIS.NS2);
This.ns2.client=this;
This.ns2.play ("Mytest2");
Vds2.addchild (VD2);
This.hbox.addChild (VDS2);
Trace ("Play two");
}
}

Private Function OnConnHandler3 (event:netstatusevent): void
{
Trace ("Connection three states:" +event.info.code);
if (event.info.code== "NetConnection.Connect.Success")
{
var vds3:videodisplay=new videodisplay ();
vds3.height=160;
vds3.width=240;
var vd3:video=new Video ();
vd3.width=240;
vd3.height=160;
This.ns3=new NetStream (THIS.NC3);
This.ns3.addEventListener (NETSTATUSEVENT.NET_STATUS,ONSTREAMHANDLER3);
Vd3.attachnetstream (THIS.NS3);
This.ns3.client=this;
This.ns3.play ("Mytest3");
Vds3.addchild (VD3);
This.hbox.addChild (VDS3);
Trace ("Play three");
}
}

Private Function OnConnHandler4 (event:netstatusevent): void
{
Trace ("Connection four status" +event.info.code);
if (event.info.code== "NetConnection.Connect.Success")
{
var vds4:videodisplay=new videodisplay ();
vds4.height=160;
vds4.width=240;
var vd4:video=new Video ();
vd4.width=240;
vd4.height=160;
This.ns4=new NetStream (THIS.NC4);
This.ns4.addEventListener (NETSTATUSEVENT.NET_STATUS,ONSTREAMHANDLER4);
Vd4.attachnetstream (THIS.NS4);
This.ns4.client=this;
This.ns4.play ("Mytest4");
Vds4.addchild (VD4);
This.hbox.addChild (VDS4);
Trace ("Play four");
}
}

Private Function OnConnHandler5 (event:netstatusevent): void
{
Trace ("Connection five Status" +event.info.code);
if (event.info.code== "NetConnection.Connect.Success")
{
var vds5:videodisplay=new videodisplay ();
vds5.height=160;
vds5.width=240;
var vd5:video=new Video ();
vd5.width=240;
vd5.height=160;
This.ns5=new NetStream (THIS.NC5);
This.ns5.addEventListener (NETSTATUSEVENT.NET_STATUS,ONSTREAMHANDLER5);
Vd5.attachnetstream (THIS.NS5);
This.ns5.client=this;
This.ns5.play ("Mytest5");
Vds5.addchild (VD5);
This.hbox.addChild (VDS5);
Trace ("Play five");
}
}

Private Function OnStreamHandler1 (event:netstatusevent): void
{
Trace ("Stream one State:" +event.info.code);
}
Private Function OnStreamHandler2 (event:netstatusevent): void
{
Trace ("Stream two states:" +event.info.code);
}
Private Function OnStreamHandler3 (event:netstatusevent): void
{
Trace ("Stream three states:" +event.info.code);
}
Private Function OnStreamHandler4 (event:netstatusevent): void
{
Trace ("Stream four states:" +event.info.code);
}
Private Function OnStreamHandler5 (event:netstatusevent): void
{
Trace ("Stream five states:" +event.info.code);
}

Third, start testing
After the builder in Flexbuilder, debug debugging.

At this point, we can see that the video can be loaded in real time in the browser, for the purpose and result of our testing, we will design the following tests to verify the results and compare them:

A, the exclusion of the server factor, that is, whether the server can provide multiple concurrent connections (to prove that the client has real-time video display is not a non-server cause)

B, Scenario one: Build 5 netconnection in Flex and 5 netstream,5 netstream points to 5 video files (Verify client connection build capability and the ability of the browser to maintain continuous concurrent connections after each connection loads the live stream)

C, Scenario two: Build 5 netconnection and 5 netstream,5 NetStream in Flex and point to a video file (verify that you can associate multiple connected concurrent connections to the same file on the server at the same time)

D, scene three: Build 1 netconnection in Flex and build 5 NetStream with this netconnection to test the performance of a video file and 5 video files respectively

E, scene Four: To change the BCD five to 3 connections and 3 streams to do a comparison test

("Two" is the as code for the B scene One, other scenes are included in the attachment, not listed here.) )

Note: The above several scenes, except a, the others are compiled separately, in the Ie8,ff,chrome test (ie also need to modify the number of connections in the registry to re-test), each individual test refresh 10 times, record the client live connection and successfully display the number of video, and in order to exclude the impact of the cache , each browser's cache is emptied before each test.

First of all to eliminate the impact of the server, we connect to the server stress test, while opening multiple browsing windows, while connecting the application, to see if it can support more than 5 video transmission, the test results are as follows (excluding server factors, proves that Flourinefx.net does not have a weird connection performance in the forum, but this is not a stress test, I am only here to prove that the server RTMP application adapter can support 5 or more real-time connections, three of the browsers open simultaneously, and access to the application, you can easily see 10 connections)

The following is a picture of several randomly intercepted test scenarios and the output in the Flex Builder console

(IE8 4 Concurrent real-time connections with 5 connections and 5 NetStream when connecting to a server without modifying the number of registry connections)

(with only one netconnection in Flex, build 5 netstream, whether connecting a file or 5 files, in each browser, only the last NetStream can connect successfully, thus proving that if you want to connect the real-time video data stream, A netconnection can be associated with only one netstream, for example)

Iv. Statistics of test results

The following is a statistical table of the test results:

IE8 before you modify the number of registry connections:

IE8 Modify the registry to change the number of connections after 10

(IE8 Registry Connection number modified: Add two DWORD under Hkey_current_user/software/microsoft/windows/currentversion/internetsettings, Maxconnectionsper1_oserver and MaxConnectionsPerServer specify their values to specify the number of connections, as follows:

)

Test data for Chrome

Test data for FF

Five, summary

1, in the development of flex, a netconnection can only be occupied by a netstream at the same time, and used to transmit real data.

2, now the browser generally can at least stably support two concurrent connections, but with some Web site said, support a few concurrent connection ability, is not stable, in my above test, five netconnection can establish success, but if use these connection channel concurrently transmit data, There is no guarantee that these concurrent connections can be successfully established every time.

Additional: I checked the relevant section of the http/1.1 RFC 8.1.4, which specifies that a single client should not have more than two connections to any server or agent (Single-user client should not maintain more than 2 connections with any server or proxy. But now the browser is basically more than the number of concurrent connections, the following is a foreign site listed on the list of browsers supported by the number of concurrent connections table:

But after my test found that for the concurrent and long-occupied connection, the browser generally only stably support two, whether it is ie\chrome\ff, and so on, perhaps the browser side of the claim to support the ability of multiple concurrent connections, for those who burst, There is no need to consume this connection for a long time to transmit large amounts of data.

It took a whole morning to do the above test, so write a summary here. Original articles, reproduced please specify. Opinions may be partial and incorrect.

Attached: Download the source files used in the test (note: The different test scenarios above please modify the introduction of different as files in Mxml)

Categories: Flex and ACTIONSCRIPT3 Learning notes, flourinefx.net usage Tags: flex, netconnection correspondence with NetStream, fluorine, fluorinefx.net, live video, Browser Concurrent Connection

The relationship between Netconnection and NetStream in Flex, and the number of browser concurrent connections test [go]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.