国产+高潮+在线,国产 av 仑乱内谢,www国产亚洲精品久久,51国产偷自视频区视频,成人午夜精品网站在线观看

gatewayWorker支持Channel分布式通訊組件嗎?

l928112133

gatewayWorker支持Channel分布式通訊組件嗎?
我看手冊(cè)里面的例子都是Workerman的,沒(méi)有g(shù)atewayworker的
能舉個(gè)例子嗎?謝謝了

2798 1 0
1個(gè)回答

keytehu

http://doc.workerman.net/components/channel-client-on.html
用法一樣吧。
start_gateway.php 所在目錄里新建一個(gè) start_channel.php。

require_once __DIR__ . '/../../vendor/autoload.php';

$channel_server = new Channel\Server('0.0.0.0', 2206);

// 如果不是在根目錄啟動(dòng),則運(yùn)行runAll方法
if(!defined('GLOBAL_START'))
{
    Worker::runAll();
}

Events.php 里

class Events {
    public static function onWorkerStart()
    {
        // Channel客戶端連接到Channel服務(wù)端
        Channel\Client::connect('127.0.0.1', 2206);
        // 訂閱broadcast事件,并注冊(cè)事件回調(diào)
        Channel\Client::on('broadcast', function($event_data)use($worker){
            // 向當(dāng)前worker進(jìn)程的所有客戶端廣播消息
            foreach($worker->connections as $connection)
            {
                $connection->send($event_data);
            }
        });
    }

    public static function onMessage ($client_id, $data)
    {
       // 將客戶端發(fā)來(lái)的數(shù)據(jù)當(dāng)做事件數(shù)據(jù)
       $event_data = $data;
       // 向所有worker進(jìn)程發(fā)布broadcast事件
       \Channel\Client::publish('broadcast', $event_data);
    }
}

試下吧

  • l928112133 2020-03-03

    好的,我試下

  • l928112133 2020-03-03

    你好,我在一個(gè)服務(wù)器上試了可以,但是我把A做服務(wù)Server,B做Client,B接受不到數(shù)據(jù)

  • keytehu 2020-04-07

    B連server的時(shí)候 Channel\Client::connect('127.0.0.1', 2206); 里的127.0.0.1要改成實(shí)際ip。并且A要把安全組和防火墻的2206端口開(kāi)放出來(lái)。

年代過(guò)于久遠(yuǎn),無(wú)法發(fā)表回答
??