我想用workerman作为客户端去订阅其他网站的信息,那边有数据就会向我发送消息,但是一直没有信息。 linux链接一段时间后就会关闭。
require_once __DIR__ . '/../Workerman/Autoloader.php'; use Workerman\Connection\AsyncTcpConnection; use Workerman\Worker; $worker = new Worker('text://0.0.0.0:6161'); $worker->onWorkerStart = function ($worker) { // ssl需要访问443端口 $access_token = '15793664'; $subscription_id = '5114dee2-eadc-4c47-bf82-6a251e04b10e'; $url = 'ws://ws.abiosgaming.com/v0?access_token=' . $access_token . '&subscription_id=' . $subscription_id; $port = '443'; echo $url . ':' . $port; $con = new AsyncTcpConnection($url . ':' . $port); // 设置以ssl加密方式访问,使之成为wss $con->transport = 'ssl'; $con->onConnect = function ($con) { $content='链接成功'; echo $content; error_log(print_r($content, 1), 3, '/home/workerman/output.log'); }; $con->onMessage = function ($con, $data) { var_export($data); error_log(print_r($data, 1), 3, '/home/workerman/output.log'); }; $con->onClose=function ($con){ $content='关闭连接'; echo $content; error_log(print_r($content, 1), 3, '/home/workerman/output.log'); }; $con->connect(); };
我看到url地址好像拼错了,地址格式是这样的才对吧 ws://ws.abiosgaming.com:443/v0?access_token=15793664&subscription_id=5114dee2-eadc-4c47-bf82-6a251e04b10e
我试试,先谢谢你哈
我试了,还是不行,没有任何输出
我这测试了下,成功了 输出了 ws://ws.abiosgaming.com:443/v0?access_token=15793664&subscription_id=5114dee2-eadc-4c47-bf82-6a251e04b10e:链接成功
<?php require_once __DIR__ . '/../Workerman/Autoloader.php'; use Workerman\Connection\AsyncTcpConnection; use Workerman\Worker; $worker = new Worker('text://0.0.0.0:6161'); $worker->onWorkerStart = function ($worker) { // ssl需要访问443端口 $access_token = '15793664'; $subscription_id = '5114dee2-eadc-4c47-bf82-6a251e04b10e'; $url = 'ws://ws.abiosgaming.com:443/v0?access_token=' . $access_token . '&subscription_id=' . $subscription_id; echo $url; $con = new AsyncTcpConnection($url); // 设置以ssl加密方式访问,使之成为wss $con->transport = 'ssl'; $con->onConnect = function ($con) { $content='链接成功'; echo $content; error_log(print_r($content, 1), 3, '/home/workerman/output.log'); }; $con->onMessage = function ($con, $data) { var_export($data); error_log(print_r($data, 1), 3, '/home/workerman/output.log'); }; $con->onClose=function ($con){ $content='关闭连接'; echo $content; error_log(print_r($content, 1), 3, '/home/workerman/output.log'); }; $con->connect(); }; Worker::runAll();
谢谢老哥了,真有心了
我看到url地址好像拼错了,地址格式是这样的才对吧
ws://ws.abiosgaming.com:443/v0?access_token=15793664&subscription_id=5114dee2-eadc-4c47-bf82-6a251e04b10e
我试试,先谢谢你哈
我试了,还是不行,没有任何输出
我这测试了下,成功了
输出了 ws://ws.abiosgaming.com:443/v0?access_token=15793664&subscription_id=5114dee2-eadc-4c47-bf82-6a251e04b10e:链接成功
谢谢老哥了,真有心了