为什么 Flash Media Server 不调用 application.onDisconnect 处理程序?

发布于 2024-07-09 23:33:39 字数 183 浏览 6 评论 0原文

我在 Flex/Flashcom 应用程序中遇到了奇怪的问题。 如果客户端应用程序意外地与服务器断开连接,后者不会调用 application.onDisconnect 处理函数。 我应该朝女巫的方向看吗? 谢谢。

更新 我没有使用服务器组件,但我确实在 Linux 上托管了这个东西。

I've run into strange problem in my Flex/Flashcom application. If client application unexpectedly disconnects from server latter does not call application.onDisconnect handler function. In witch direction should I look? Thank you.

Update I'm not using server components, but I do host this thing on Linux.

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

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

发布评论

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

评论(3

土豪 2024-07-16 23:33:39

如果是这样,则会记录下来并 这里是一个值得关注的有趣论坛..基本上在 Linux 上它可能工作得有点疯狂:)

If so, it's documented and here an interesting forum to follow..basically on Linux it may work a bit crazy like :)

帥小哥 2024-07-16 23:33:39

在(Flash Media-)服务器“知道”这一点之前,客户端可能会断开连接。 因此,直到非常非常晚才会调用“onDisconnect”函数(客户端永远不会调用它)。

如果您想尽早检测(并采取行动)“挥之不去”的断开连接,请使用 client.getStats() 方法。

我有一个服务器端动作脚本示例:

// add method to standard class
Client.prototype.isAlive = function() {
        var stats = this.getStats();
        var timeout_value = 3 * 1000;  // in ms.
        //trace('Measured timeout: ' + stats['ping_rtt']);
        if (stats)
                return (stats['ping_rtt'] < timeout_value);
}

// use this in an interval which traverses the application.clients list
if (! client.isAlive())
    application.disconnect(client);

您可以通过从已连接的 Flash 客户端移除网络电缆来触发和测试此“缺少 onDisconnect”行为。

It's possible that a client is disconnected before the (Flash Media-) server 'knows' about this. So no 'onDisconnect' function gets invoked (it never gets called by the client) until very, very late.

If you want to detect (and act upon) "lingering" disconnects early, use the client.getStats() method.

I have this server-side actionscript example:

// add method to standard class
Client.prototype.isAlive = function() {
        var stats = this.getStats();
        var timeout_value = 3 * 1000;  // in ms.
        //trace('Measured timeout: ' + stats['ping_rtt']);
        if (stats)
                return (stats['ping_rtt'] < timeout_value);
}

// use this in an interval which traverses the application.clients list
if (! client.isAlive())
    application.disconnect(client);

You can trigger and test this 'missing onDisconnect' behavior by removing the network cable from the connected Flash client.

情何以堪。 2024-07-16 23:33:39

正如Artem Tikhomirov(问题的作者)在他的自己的答案,我的答案没有帮助(我将其作为维基保留在下面,以供存档)。

关于Ric Tokyo给出了真正的答案questions/359727#486550">Linux 上的错误,并记录在 此线程

我的答案被“选择”的唯一原因是因为 Artem 在 7 天限制之前没有选择任何其他答案(或他自己的答案),给了我(第一个也是最多投票的答案)一半的赏金分(超过 75 分) 150) 自动,如此博客条目中所述一个>。


第一条线索:

如果客户端是基于组件的应用程序,则需要[正确处理连接事件][9]。

当您开发应用程序时,请注意使用组件会引入显式的 onConnectAcceptonConnectReject 事件。

您需要包含处理这些事件的代码。
使用组件时,必须修改服务器端代码中的 application.onConnect 语句以包含 application.onConnectAcceptapplication.onConnectReject事件处理程序。
onConnect 处理程序的最后一行(按执行顺序)应该是 application.acceptConnection()application.rejectConnection()。< /p>

如果您的应用程序需要在显式 acceptConnection()rejectConnection() 方法之后添加其他代码,例如指示用户已被授予或拒绝权限的消息对于应用程序,您应该将该代码放置在 application.onConnectAcceptapplication.onConnectReject 语句中。

提示:如果您不使用媒体组件,则无法使用 application.onConnectAcceptapplication.onConnectReject


然后,您可能需要检查 Flash 输出面板中的任何错误消息,例如:

Error #2044: NetStatusEvent non pris en charge : level=error, code=NetStream.Play.Failed
    at MethodInfo-1()
Error #2044: NetStatusEvent non pris en charge : level=error, code=NetStream.Record.NoAccess
    at MethodInfo-1()

这将指示客户端未考虑服务器异常,从而强制意外退出。

如果客户端从服务器读取流,则必须确保:

  • NetConnection 已成功
  • NetStreams(输入和输出)侦听 NET_STATUS

一个好的代码应该是这样的:

var status:Function = function( e:NetStatusEvent ):void
{
    trace( "status : " + e.info.code ) ;
    if ( e.info.code == "NetConnection.Connect.Success" )
    {
        streamOut = new NetStream( nc ) ;
        streamOut.addEventListener( NetStatusEvent.NET_STATUS , status ) ;
 
        streamIn  = new NetStream( nc ) ;
        streamIn.addEventListener( NetStatusEvent.NET_STATUS , status ) ;
 
        streamOut.attachCamera( cam ) ;
        video.attachNetStream( streamIn ) ;
 
        streamOut.publish( "private" ) ;
        streamIn.play( "private" ) ;       
    }
}

由于 FlashPlayer 的新版本确实会传播此类异常,因此它们必须被监控然后在客户端应用程序中捕获

As mentioned by Artem Tikhomirov (the author of the question) in his own answer, my answer is not helpful (I keep there below as wiki, for archive).

The real answer has been given by Ric Tokyo regarding a bug on Linux, and is documented in this thread.

The only reason my answer is "chosen" is because Artem did not choose any other answer (or an answer of his own) before the 7 day limits, giving me (the first and most upvoted answer) half of the bounty points (75 over 150) automatically as explained in this SO blog entry.


First lead:

If the client is a component-base application, it needs to [handle connection events properly][9].

When you develop applications, be aware that using components introduces explicit onConnectAccept and onConnectReject events.

You need to include code to handle these events.
When you use components, you must modify the application.onConnect statement in your server-side code to include the application.onConnectAccept and application.onConnectReject event handlers.
The last line (in order of execution) of your onConnect handler should be either application.acceptConnection() or application.rejectConnection().

If your application requires additional code following the explicit acceptConnection() or rejectConnection() methods, such as a message indicating that the user has been granted or denied permission to the application, you should place that code in the application.onConnectAccept or application.onConnectReject statements.

TIP: If you're not using media components, you cannot use application.onConnectAccept and application.onConnectReject.


Then, you may want to check any error message in the Flash output panel, like:

Error #2044: NetStatusEvent non pris en charge : level=error, code=NetStream.Play.Failed
    at MethodInfo-1()
Error #2044: NetStatusEvent non pris en charge : level=error, code=NetStream.Record.NoAccess
    at MethodInfo-1()

That would indicate a server exception non-taken into account by the client, forcing an unexpected exit.

If the client read a stream from the server, it must make sure:

  • the NetConnection has succeeded
  • the NetStreams (in and out) listen to NET_STATUS

A good code would like this:

var status:Function = function( e:NetStatusEvent ):void
{
    trace( "status : " + e.info.code ) ;
    if ( e.info.code == "NetConnection.Connect.Success" )
    {
        streamOut = new NetStream( nc ) ;
        streamOut.addEventListener( NetStatusEvent.NET_STATUS , status ) ;
 
        streamIn  = new NetStream( nc ) ;
        streamIn.addEventListener( NetStatusEvent.NET_STATUS , status ) ;
 
        streamOut.attachCamera( cam ) ;
        video.attachNetStream( streamIn ) ;
 
        streamOut.publish( "private" ) ;
        streamIn.play( "private" ) ;       
    }
}

Since the new versions of FlashPlayer do propagate those kind of exception, they must be monitored and then catch in the client application

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