我采用workerman 作为客户端从其他服务端接收数据并处理,需要作为客户机同时连接两个不同的socket服务端,请问有方式实现吗?
https://www.workerman.net/doc/workerman/faq/as-wss-client.html 手册有
谢谢,费心了
如下Eg仅做参考:
<?php require_once __DIR__ . './autoroad.php'; use Workerman\Worker; use Workerman\Connection\AsyncTcpConnection; $worker1 = new Worker(); $worker1->onWorkerStart = function ($worker) { //global $con1, $con2; $con1 = new AsyncTcpConnection('tcp://127.0.0.1:4444'); $con1->onConnect = function(AsyncTcpConnection $con) { $con->send('hello 444444'); }; $con1->onMessage = function(AsyncTcpConnection $con, $data) { //tcp://127.0.0.1:4444接收服务过来的数据 echo $data; echo "!!!!!!!!!!!!!!"; }; $con1->connect(); $con2 = new AsyncTcpConnection('tcp://127.0.0.1:5555'); $con2->onConnect = function(AsyncTcpConnection $con) { $con->send('hello 55555555'); }; $con2->onMessage = function(AsyncTcpConnection $con, $data) { //tcp://127.0.0.1:5555接收服务过来的数据 echo $data; echo "@@@@@@@@@@@@@"; }; $con2->connect(); }; $worker2 = new Worker("tcp://0.0.0.0:4444"); $worker2->onMessage = function($connection, $data) { // 接收客户端过来的数据 var_dump($data); //向客户端发送 $connection->send('44444444444444 hello'); }; $worker3 = new Worker("tcp://0.0.0.0:5555"); $worker3->onMessage = function($connection, $data) { // 接收客户端过来的数据 var_dump($data); //向客户端发送 $connection->send('55555555555 hello'); }; Worker::runAll();
https://www.workerman.net/doc/workerman/faq/as-wss-client.html
手册有
谢谢,费心了
如下Eg仅做参考:
谢谢,费心了