检测(在服务器端)Flex 客户端何时与 BlazeDS 目标断开连接

发布于 2024-08-22 18:29:41 字数 274 浏览 6 评论 0原文

我想知道是否可以轻松检测(在服务器端)Flex 客户端何时与 BlazeDS 目标断开连接?我的情况很简单,我想尝试使用它来计算每个客户端在每个会话中连接的时间。我还需要能够区分客户端(即,不仅仅是计算我在 ds-console 中看到的当前连接的客户端数量)。

虽然我可以在客户端的“我现在注销”过程中进行编程,但我不知道如果客户端只是导航到另一个网页而不是执行所述注销过程,这是否会触发。

任何人都可以建议是否有一种简单的方法可以在服务器端进行这种类型的监控。

非常感谢, 亚历克斯

I'd like to know whether it's possible to easily detect (on the server side) when Flex clients disconnect from a BlazeDS destination please? My scenario is simply that I'd like to try and use this to figure out how long each of my clients are connected for each session. I need to be able to differentiate between clients as well (ie so not just counting the number of currently connected clients which I see in ds-console).

Whilst I could program in a "I'm now logging out" process in my clients, I don't know whether this will fire if the client simply navigates away to another web page rather than going though said logout process.

Can anyone suggest if there's an easy way to do this type of monitoring on the server side please.

Many thanks,
Alex

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

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

发布评论

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

评论(3

站稳脚跟 2024-08-29 18:29:41

实现您自己的适配器扩展“extends ServiceAdapter”

然后设置函数:

@Override
公共布尔handlesSubscriptions(){
返回真;
}
这样你就可以处理订阅和取消订阅

然后你可以在管理功能中管理它们:

@Override
公共对象管理(CommandMessage commandMessage) {

switch (commandMessage.getOperation()) {
案例 CommandMessage.SUBSCRIBE_OPERATION:
休息;
案例 CommandMessage.UNSUBSCRIBE_OPERATION:
休息;
还可以捕获不同的命令

希望这有帮助

Implement you own adapter extending "extends ServiceAdapter"

Then set the function:

@Override
public boolean handlesSubscriptions() {
return true;
}
So you can handle subscription and unsubscription

Then you can manage those in the manage function:

@Override
public Object manage(CommandMessage commandMessage) {

switch (commandMessage.getOperation()) {
case CommandMessage.SUBSCRIBE_OPERATION:
break;
case CommandMessage.UNSUBSCRIBE_OPERATION:
break;
}

}

You can also catch different commands.

Hope this help

得不到的就毁灭 2024-08-29 18:29:41

正确执行此操作的唯一方法是以某种方式实现心跳机制。您可以按照之前的建议使用 http 的保持活动状态以及会话过期,但我的意见是使用 BlazeDS 的消息传递机制(在 X 秒发送消息)。您可以控制时间间隔和其他方面(也许您想检测客户端是否在几个小时内没有执行任何操作,并让会话无效,即使您的客户端仍然处于连接状态)。

如果您想在客户端断开连接时立即收到通知(聊天应用程序),解决方案是使用套接字(RTMP)或某种仿真(http 流),它们将立即检测客户端是否断开连接,但是这种断开可能是暂时的(也许网络宕机了一秒钟,之后就没问题了,你也应该检测到这一点)。

The only way to do it right is to implement the heartbeat mechanism in a way or another. You can use the keep-alive from http coupled with session expire as suggested before but my opinion is to use the messaging mechanism from BlazeDS (send a message at X seconds). You can control the time interval and other aspects (maybe you want to detect if the client is not doing anything for several hours and to invalidate the session even if your client is still connected).

If you want to be notified instantly (chat application) when a client is disconnecting a solution is to have a socket (RTMP) or some emulation (http streaming) which will detect instantly if the client is disconnected, however this disconnection can be temporary (maybe the network was down for one second, and after that is ok, and you should also detect that).

¢蛋碎的人ぎ生 2024-08-29 18:29:41

我假设 BlazeDS 会在客户端断开连接时提供回调或事件,但我没有使用过 Blaze,所以这只是一个猜测。第一步是检查文档,看看它是否确实如此,因为这将是您最好的选择。

在没有断开连接事件(或者不可靠)的情况下,我所做的就是添加一条保持活动消息。例如,客户端将配置为每 30 秒发送一条保活消息,如果服务器超过 2 分钟没有看到保活消息,则假定客户端已断开连接。这可以让您区分不同的客户,并且您可以调整费率和检查时间以获得您满意的服务。

I would assume BlazeDS would provide a callback or event for when a client disconnects, but I haven't worked with Blaze so that would just be a guess. First step would be to check the documentation to see if it does though, as that would be your best bet.

What I've done in cases where there isn't a disconnect event (or it's not reliable) is to add a keepalive message. For instance, the client would be configured to send a keepalive message every 30 seconds, and if the server goes more than, say, 2 minutes without seeing a keepalive then it assumes the client has disconnected. This would let you differentiate between different clients, and you can play around with the rate and check times to get something you're happy with.

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