A、B服务器安装了webman的GatewayWorker插件,怎么用sendToClient发消息

fantasmic

问题描述

A、B服务器可以通过内网IP访问,A服务器和客户端建立连接,B服务器想通过sendToClient给客户端发消息,
A、B的process.php要怎么配置呢

return [
    'gateway' => [
        'handler'     => Gateway::class,
        'listen'      => 'websocket://0.0.0.0:7272',
        'count'       => cpu_count(),
        'reloadable'  => false,
        'constructor' => ['config' => [
            'lanIp'           => '127.0.0.1',
            'startPort'       => 2300,
            'pingInterval'    => 20,
            'pingNotResponseLimit' => 1,
            'pingData'        => '',
            'registerAddress' => '127.0.0.1:1236',
            'onConnect'       => function(){},
        ]]
    ],
    'worker' => [
        'handler'     => BusinessWorker::class,
        'count'       => cpu_count()*2,
        'constructor' => ['config' => [
            'eventHandler'    => plugin\webman\gateway\Events::class,
            'name'            => 'ChatBusinessWorker',
            'registerAddress' => '127.0.0.1:1236',
        ]]
    ],
    'register' => [
        'handler'     => Register::class,
        'listen'      => 'text://127.0.0.1:1236',
        'count'       => 1, // Must be 1
        'constructor' => []
    ]
]
366 1 0
1个回答

walkor 打赏

B不用设置process,B服务器使用gatewayClient就可以给A服务器的客户端发消息。
https://www.workerman.net/doc/gateway-worker/push-in-other-project.html

  • fantasmic 2024-03-11

    还有个问题,A服务器的1236端口在云服务商和宝塔都放行了,但在B服务器telnet端口不通呢

  • fantasmic 2024-03-11

    解决了,要把A服务器register监听改为0.0.0.0:1236

×
🔝