AS3 事件中的超时

发布于 2024-10-31 02:15:40 字数 967 浏览 0 评论 0原文

我有一个 NetConnection 对象:

myNetConnection = new NetConnection();
myNetConnection.addEventListener(NetStatusEvent.NET_STATUS, statusHandler);
myNetConnection.connect("rtmp://address");

并在处理程序中执行以下操作:

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

所以,如果一切正常 - 我很快就会在调试控制台中看到“ok”。 但如果有任何问题 - “一些问题,NetConnection.Connect.Failed”我在长时间等待后看到。 我的问题 - 我如何才能更快地看到“一些问题,NetConnection.Connect.Failed”(如“ok”快速)?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浪荡不羁 2024-11-07 02:15:40

你很可能不能。该事件会尽可能快地触发,连接失败需要很长时间才能显现出来。

在我看来,问题在于连接尝试超时。 Flash 尝试连接并设置计时器,如果在建立连接之前计时器触发,Flash 会得出资源不可用的结论。您不能立即失败,因为在计时器触发之前连接不会失败。

Flash 无法立即告诉您资源不可用,因为有时服务器会在几毫秒内响应,但有时可能需要几秒钟。

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.

昔日梦未散 2024-11-07 02:15:40

这里的问题是,如果 Flash Player 无法使用正常协议(RTMP,端口 1935)连接到服务器,它会自动尝试使用后备协议和端口建立连接。正常的顺序是:

netConnection.connect("rtmp://myserver/myapp");
// 使用默认端口1935
netConnection.connect("rtmp://myserver:443/myapp");
netConnection.connect("rtmp://myserver:80/myapp");
netConnection.connect("rtmpt://myserver:80/myapp");

所有这些尝试都会增加连接的最终超时。

发生此自动重试序列
仅当初始连接
指定RTMP协议并使用
默认端口——例如,
my_nc.connect(“rtmp://myserver/myapp”)。

您可以在此处找到更多信息。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文