Django频道 - 可能“仅写”频道组?

发布于 2025-02-10 02:10:45 字数 265 浏览 4 评论 0原文

希望这是有道理的。我正在使用Django渠道构建一个应用程序,该应用程序有点像测验 - 有一个主机和多个玩家。当房子的玩家一侧出现问题时,我希望特定的玩家消费者向主机组发送消息 - 这很容易。不幸的是,由于所有玩家消费者都需要附加到主机组以发送消息,因此他们也会接收这些消息并将其发送给其连接的客户。因此,如果播放器1的消费者发生问题,当我要做的就是提醒主机时,它最终会被广播给玩家2,播放器3等。

我已经考虑过在这样的消息中使用“无手”标志来执行此操作,但是是否有一种更干净的方法可以做我想要的事情?

Hopefully this is gonna make sense. I am building an app using django-channels that works a little bit like a quiz - there is a host, and multiple players. When something goes wrong in the player side of the house I want the specific player consumer to send a message to the host group - which is easy enough. Unfortunately, because all player consumers need to be attached to the host group to send messages, they also receive those and send them to their connected clients. Thus if an issue occurs with player 1's consumer, it ultimately gets broadcast to player 2, player 3, etc, when all I want to do is alert the host.

I've thought about doing this with a 'no-handle' flag in such messages, but is there a cleaner method of doing what I want?

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

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

发布评论

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

评论(1

雪化雨蝶 2025-02-17 02:10:45

事实证明,这比我预期的要简单得多。 group_add()订阅消息,但是如果没有该步骤,仍然可以group_send()到组 - 因此可以将异常处理播放器1发送到主机组没有任何玩家在该组中收到消息。

Turns out this was a lot simpler than I expected. group_add() subscribes to messages, but without that step it is still possible to group_send() to a group - so an exception processing player 1 can be sent to the host group without any players receiving messages in that group.

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