1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > php socket端口监听端口号 swoole websocket服务器中添加监听tcp的端口

php socket端口监听端口号 swoole websocket服务器中添加监听tcp的端口

时间:2021-12-18 13:28:24

相关推荐

php socket端口监听端口号 swoole websocket服务器中添加监听tcp的端口

在websocket服务器中监听tcp的9501端口代码如下:

$aa = $this->server->listen('127.0.0.1',9501,SWOOLE_SOCK_TCP);

$aa->set([

'open_length_check' => true,

'package_length_type' => 'N',

'package_length_offset' => 0,

'package_max_length' => 8000000,

]);

$aa->on('receive',function ($serv,$fd,$from_id,$data){

$websocket = $this->server->ports[0];

foreach ($websocket->connections as $_fd) {

var_dump($_fd);

if ($server->exist($_fd)) {

$server->push($_fd, "this is server onReceive");

}

}

});

$this->server->on('close', function ($ser, $fd) {

echo "client {$fd} closed\n";

});

报错信息是:

[-06-05 09:25:22 #12948.3] WARNING swProtocol_recv_check_length (ERRNO 1201): package is too big, remote_addr=unknown:0, length=1751477360

就是个普通的监听,包能到达1个g,请问这是不是不正常

swoole 客户端:

$client = new Swoole\Client(SWOOLE_SOCK_TCP);

if (!$client->connect('127.0.0.1', 9501, -1)) {

exit("connect failed. Error: {$client->errCode}\n");

}

$client->send("hello world\n");

//echo $client->recv();

$client->close();

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。