I have a NetConnection object:
myNetConnection = new NetConnection();
myNetConnection.addEventListener(NetStatusEvent.NET_STATUS, statusHandler);
myNetConnection.connect("rtmp://address");
And in handler do this:
private function statusHandler(event:NetStatusEvent):void
{
switch (event.info.code)
{
case "NetConnection.Connect.Success":
{
trace("ok");
开发者_运维知识库 break;
}
case "NetConnection.Connect.Failed":
{
trace("Some problems, NetConnection.Connect.Failed");
break;
}
}
}
So, if all ok - I have see "ok" in debug console very fast. But if have any problems - "Some problems, NetConnection.Connect.Failed" I see after long time waiting. My question - how i can see "Some problems, NetConnection.Connect.Failed" faster(as "ok" fast)?
You most likely can't. The event is triggered as fast as it can be, it's the connection failure that is taking a long time to manifest itself.
It looks to me like the problem is that the connection attempt times out. Flash tries to connect and sets a timer, if the timer fires before the connection is established Flash concludes that the resource is not available. You can't get a failure at once, because the connection does not fail until the timer has fired.
Flash can't tell you immediately that the resource is not available because sometimes a server responds within milliseconds, but sometimes it can take seconds.
The problem here is that if Flash Player fails to connect to the server with the normal protocol (RTMP, port 1935) it automatically tries to establish a connection using fallback protocols and ports. The normal sequence is:
netConnection.connect("rtmp://myserver/myapp"); // uses the default port 1935 netConnection.connect("rtmp://myserver:443/myapp"); netConnection.connect("rtmp://myserver:80/myapp"); netConnection.connect("rtmpt://myserver:80/myapp");
All this attempts increase the final timeout for the connection.
This automatic retry sequence occurs only if the initial connection specifies the RTMP protocol and uses the default port--for example, my_nc.connect("rtmp://myserver/myapp").
You can found more information here.
精彩评论