user696297
user696297

Reputation: 1

Timeout in AS3 events

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)?

Upvotes: 0

Views: 2368

Answers (2)

bmleite
bmleite

Reputation: 26880

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.

Upvotes: 2

Theo
Theo

Reputation: 132862

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.

Upvotes: 2

Related Questions