### 问题描述
swoole主服务器是websocket服务器,设置内部监听的回调不生效
### Swoole4.4.2版本,PHP7.2.4版本,操作系统ubuntu18.04
### 相关代码
```php
$this->innerServer = $this->server->addListener($innserConf['host'],$innserConf['port'],SWOOLE_SOCK_TCP);
if(empty($innserConf['set'])){
exit;
}
$this->innerServer->set($innserConf['set']);
$this->innerServer->on('connect', [$this, 'onInnerConnect']);
$this->innerServer->on('receive', [$this, 'onInnerReceive']);
$this->innerServer->on('close', [$this, 'onInnerClose']);
$this->innerServer->on('open', [$this, 'onInnerOpen']);
内部监听的配置信息:
'innser_connect' => [
'host' => '127.0.0.1',
'port' => 9511,
'set' => [
//最大请求次数 0:无上限
'max_request' => 0,
//心跳频次
'heartbeat_check_interval' => 60,
//心跳空闲时间
'heartbeat_idle_time' => 120,
]
]
内部监听的回调函数:
/**
* business server连接
* @param \Swoole\Server $server
* @param int $fd
*/
public function onInnerConnect(\Swoole\Server $server, int $fd)
{
$this->logPrint(LOG_NOTICE, 'inner client connected');
$this->innerClientFd->set($this->server->host.":".$this->server->port."-".$this->server->workerId,$fd);
}
public function onInnerReceive(\Swoole\Server $server, int $fd,int $from_id,$data)
{
var_dump($data);
}
public function onInnerClose(\Swoole\Server $server, $fd)
{
echo "{$fd}Client: Close.\n";
}
客户端:
public function init()
{
$this->client = new \Swoole\Client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_ASYNC);
$this->client->set([
'open_length_check' => true,
'package_length_type' => 'N',
'package_length_offset' => 0,
'package_body_offset' => 4,
'package_max_length' => 81920,
]);
$this->client->host = $this->servHost;
$this->client->port = $this->servPort;
$this->client->on('connect',[$this,'onConnect']);
$this->client->on('receive',[$this,'onReceive']);
$this->client->on('close',[$this,'onClose']);
$this->client->on('error',[$this,'onError']);
$this->client->connect($this->servHost,$this->servPort);
}
public function onError(\Swoole\Client $client)
{
echo "内部出错";
}
public function onConnect(\Swoole\Client $client)
{
echo "内部链接成功:{$this->servHost}:{$this->servPort}";
}
public function onReceive(\Swoole\Client $client)
{
}
public function onClose(\Swoole\Client $client)
{
echo "内部链接关闭";
}
```