AS3 事件中的超时
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你很可能不能。该事件会尽可能快地触发,连接失败需要很长时间才能显现出来。
在我看来,问题在于连接尝试超时。 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.
这里的问题是,如果 Flash Player 无法使用正常协议(RTMP,端口 1935)连接到服务器,它会自动尝试使用后备协议和端口建立连接。正常的顺序是:
所有这些尝试都会增加连接的最终超时。
您可以在此处找到更多信息。
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:
All this attempts increase the final timeout for the connection.
You can found more information here.