yonghu.php
907 字节
<?php
require_once __DIR__ . '/simplewind/vendor/autoload.php';
require_once __DIR__ . '/simplewind/vendor/workerman/workerman/Autoloader.php';
use Workerman\Worker;
use Workerman\Connection\AsyncTcpConnection;
use think\Db;
use Workerman\Lib\Timer;
$worker = new Worker();
$worker->onWorkerStart = function($worker){
// 设置访问对方主机的本地ip及端口(每个socket连接都会占用一个本地端口)
$context_option = array(
'socket' => array(
// ip必须是本机网卡ip,并且能访问对方主机,否则无效
'bindto' => '114.215.223.17:5002',
),
);
$con = new AsyncTcpConnection('ws://114.215.223.17:5001', $context_option);
$con->onConnect = function($con) {
$con->send('hello');
};
$con->onMessage = function($con, $data) {
echo $data;
};
$con->connect();
};
Worker::runAll();