php - Ratchet 中的实时一对一消息

标签 php ratchet

我只是在学习 Ratchet(用于 PHP 实时聊天应用程序的库)。根据文档,以下函数将收到两件事:

  • 消息来自谁和
  • 信息。

  • 然而,它错过了发送给谁。此功能将消息发送给所有连接的人。但我也想实现一对一聊天。有没有办法做到这一点?

    这是该库的链接:http://socketo.me/docs/hello-world .
    public function onMessage(ConnectionInterface $from, $msg) {
        //send the message to all the other clients except the one who sent.
        foreach ($this->clients as $client) {
            if ($from !== $client) {
                $client->send($msg);
            }
        }
    }
    

    最佳答案

    我建议您根据用户想要的每次聊天进行不同的订阅。

    每个人之间的聊天消息的一个 channel :subscriptionname = room123

    对于每个个人聊天,您可以使用不同的签名:subscriptionname = personal456。

    然后让您的客户端应用程序监听 2 个不同的订阅,并尝试根据收到消息的订阅的名称对其进行路由。

    关于php - Ratchet 中的实时一对一消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36475593/

    相关文章:

    node.js - 想从: Node. js Meteor.js Ratchet RabbitMQ for Real-time WebChat中选择(论坛)

    multithreading - 使用 angularJS 应用程序提高 Symfony2 的性能

    php生成一个字符串并从mysql中检查不存在

    php - MYSQL 匹配示例不工作。 "Spa"是停用词吗?

    php - 如何将 base64 导出的公钥转换为我可以在 php 中使用的内容?

    javascript - 重定向到 cordova 应用程序中的另一个页面后无法运行 javascript

    php - 使用 Ratchet 通过 websockets 使用 PHP 流式传输视频

    php - Symfony2 WebSocketBundle - ZMQ 推送不起作用

    javascript - jQuery Sortable 只有一个列表如果取消仍然更新

    php - 在 jQuery ajax 请求中保护和/或加密(隐藏)POST 变量