相关疑难解决方法(0)

定期向 Ratchet 中的客户端发送消息

我正在尝试定期发送“hello world!” 从 Ratchet 教程向连接到聊天服务器的所有客户端发送消息

我将在这里发布所有代码:Chat.php:

<?php
namespace MyApp;
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;

class Chat implements MessageComponentInterface {
    public $clients;

    public function __construct() {
        $this->clients = new \SplObjectStorage;
            }

    public function onOpen(ConnectionInterface $conn) {
        // Store the new connection to send messages to later
        $this->clients->attach($conn);

        echo "New connection! ({$conn->resourceId})\n";
    }

    //this worked but I don't want this behaviour
    public function onMessage(ConnectionInterface $from, $msg) {
        /*$numRecv = count($this->clients) - 1;
        echo sprintf('Connection %d sending message "%s" to %d other connection%s' . …
Run Code Online (Sandbox Code Playgroud)

php web-services websocket ratchet

4
推荐指数
1
解决办法
4150
查看次数

标签 统计

php ×1

ratchet ×1

web-services ×1

websocket ×1