我这边发现一个问题,我把配置里gateway-worker端口1236设置为了12360,启动这些都正常,但是在我使用gateway发送消息时,仍然调用的是1236这个端口,导致不断报错。后来我去vendor/workerman/gateway-worker/src/Lib/Gateway.php下把端口也改为12360才恢复正常
<?php
use Webman\GatewayWorker\Gateway;
use Webman\GatewayWorker\BusinessWorker;
use Webman\GatewayWorker\Register;
return [
'gateway' => [
'handler' => Gateway::class,
'listen' => 'websocket://0.0.0.0:12720',
'count' => cpu_count(),
'reloadable' => false,
'constructor' => ['config' => [
'lanIp' => '127.0.0.1',
'startPort' => 13000,
'pingInterval' => 25,
'pingData' => '{"type":"ping"}',
'registerAddress' => '127.0.0.1:12360',
'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:12360',
]]
],
'register' => [
'handler' => Register::class,
'listen' => 'text://127.0.0.1:12360',
'count' => 1, // Must be 1
'constructor' => []
],
];
namespace GatewayWorker\Lib;
use Exception;
use GatewayWorker\Protocols\GatewayProtocol;
use Workerman\Connection\TcpConnection;
/**
* 数据发送相关
*/
class Gateway
{
/**
* gateway 实例
*
* @var object
*/
protected static $businessWorker = null;
/**
* 注册中心地址
*
* @var string|array
*/
public static $registerAddress = '127.0.0.1:12360';
/**
* 秘钥
* @var string
*/
public static $secretKey = '';
/**
* 链接超时时间
* @var int
*/
public static $connectTimeout = 3;
/**
* 与Gateway是否是长链接
* @var bool
*/
public static $persistentConnection = true;
情况发生在我调用了Gateway::ungroup($groupName);就会报错error:stream_socket_client(): Unable to connect to tcp://127.0.0.1:1236 (由于目标计算机积极拒绝,无法连接。)。事实上我早就在配置里把端口改为了12360
使用的webman官方最新版本,在webman里安装的gateway-worker。系统是在本地电脑win10系统
businessWorker进程里的业务代码可以自动识别regsiter端口。
其它进程的业务代码需要手动设置 Gateway::$registerAddress='127.0.0.1:xxx';用来标记到底是向哪个gatewayWorker发送数据。有这个设置机制因为其它进程无法获知regsiter地址,并且可能部署了多个gatewayWorker,甚至GatewayWorker不在本服务器。
明白了 感谢大佬,我的确是在外部直接调用的gateway,没有重新手动设置地址