AsyncTcpConnection 链接火币websocket

0

function subscribe($callback, $sub_str="market.btcusdt.kline.1min") {
$GLOBALS['sub_str'] = $sub_str;
$GLOBALS['callback'] = $callback;
$worker = new Worker();
$worker->onWorkerStart = function($worker) {
// ssl需要访问443端口
//$con = new AsyncTcpConnection('ws://api.huobi.pro/ws');
$con = new AsyncTcpConnection('ws://api.huobi.de.com/ws');


    // 设置以ssl加密方式访问,使之成为wss
$con->transport = 'ssl';

$con->onConnect = function($con) {
$data = json_encode([
'sub' => $GLOBALS['sub_str'],
'id' => 'depth' . time()
]);
$con->send($data);
};

$con->onMessage = function($con, $data) {
$data = gzdecode($data);
$data = json_decode($data, true);
if(isset($data['ping'])) {
echo "send pong \n";
$con->send(json_encode([
"pong" => $data['ping']
]));
}else{
call_user_func_array($GLOBALS['callback'], array($data));
}
};

$con->onClose = function($con) {
echo "reConnect \n";
// 如果连接断开,则在1秒后重连
$con->reConnect(5);
};

$con->connect();
};

Worker::runAll();

}
这个是火币官网demo
本地和api.huobi.de.com这个地址的网络不稳定
我使用windows 跑一会自己就停止了,也不重连
看日志貌似就卡在了onmessage
是他们服务端问题还是什么问题


截图
貌似系统没有捕获到断开信号

已邀请:

要回复问题请先登录注册