您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
workerman类TcpConnection的接口getRemotePort获取远端对端端口
发布时间:2021-12-03 23:37:34编辑:雪饮阅读()
getRemotePort
说明:
int Connection::getRemotePort()
获得该连接的客户端端口
参数
无参数
实例:
<?php
use Workerman\Worker;
use Workerman\Connection\TcpConnection;
require_once __DIR__ . '/vendor/autoload.php';
$worker = new Worker('websocket://0.0.0.0:8484');
$worker->onConnect = function(TcpConnection $connection)
{
echo "new connection from address " .
$connection->getRemoteIp() . ":". $connection->getRemotePort() ."\n";
};
// 运行worker
Worker::runAll();
?>
实例运行并有两个websocket客户端连接时:
[root@izj6c2jeancylo0ppo4vz5z workerman]# php test.php start
Workerman[test.php] start in DEBUG mode
------------------------------------------- WORKERMAN --------------------------------------------
Workerman version:4.0.22 PHP version:7.0.33
-------------------------------------------- WORKERS ---------------------------------------------
proto user worker listen processes status
tcp root none websocket://0.0.0.0:8484 1 [OK]
--------------------------------------------------------------------------------------------------
Press Ctrl+C to stop. Start success.
new connection from address 119.122.90.118:13385
new connection from address 119.122.90.118:13896
关键字词:workerman,TcpConnection,getRemotePort
相关文章
- workerman类TcpConnection的接口close
- workerman类TcpConnection的maxSendBufferSize属性(缓
- workerman类TcpConnection的maxPackageSize属性(最大
- workerman类TcpConnection的defaultMaxSendBufferSize
- workerman类AsyncTcpConnection的__construct方法实现
- workerman类AsyncTcpConnection的__construct方法实现
- workerman接口listen实现内外部通信(管理后台或系统向w
- php或workerman利用posix_getpid函数获取进程id
- workerman回调onBufferFull(缓冲区溢出)
- workerman回调onBufferFull默认缓冲区大小配置