你好,想问下workerman作为客户端连接对方的服务端没有进入onConnect是怎么回事?
function subscribe($callback, $sub_str="") {
$GLOBALS['sub_str'] = $sub_str;
$GLOBALS['callback'] = $callback;
$worker = new Worker();
if(isset(Config::$config['paper'])){
$url = "";
}else{
$url = "";
}
try {
$worker->onWorkerStart = function($worker) use ($url){
// ssl需要访问443端口
$con = new AsyncTcpConnection($url);
$ntime = $this->getTimestamp();
print_r($ntime." $url\n");
// 设置以ssl加密方式访问,使之成为wss
$con->transport = 'ssl';
// 定时器
Timer::add(20, function() use ($con)
{
$con->send("ping");
//
$ntime = $this->getTimestamp();
print_r($ntime." ping\n");
});
$con->onConnect = function($con){
$data = json_encode([
'op' => "subscribe",
// 'args' => $GLOBALS['sub_str']
'args' => [
$GLOBALS['sub_str']
]
]);
$data = stripslashes($data);
// $data = substr($data,1,strlen());
$data = '{"op":"subscribe","args":[{'.substr($data,28,-4).'}]}';
$ntime = $this->getTimestamp();
print_r($ntime . " $data\n");
$con->send($data);
// $con->send($data);
};
$con->onMessage = function($con, $data) {
// 如果是深度200档,则校验
if(strpos($data,"checksum"))
{
$ntime = $this->getTimestamp();
print_r($ntime . " $data\n");
if ($this->partial==null)
{
$this->partial=$data;
}else{
$update = $data;
// 深度合并
$data = $this->checksumTest->depthMerge($this->partial,$update);
// 深度校验结果
$result = $this->checksumTest->checksum($data);
if ($result){
print_r(self::getTimestamp()." checksum success\n");
} else {
die(self::getTimestamp()." checksum fail\n");
}
print_r("---------------------------------------------------------------\n");
// 打印增量数据
call_user_func_array($GLOBALS['callback'], array($update));
// 更新全局的全量数据
$this->partial = $data;
}
}else{
$ntime = $this->getTimestamp();
print_r($ntime . " $data\n");
}
};
$con->onClose = function ($con) {
$ntime = $this->getTimestamp();
print_r($ntime." reconnecting\n");
$con->reConnect(0);
};
$con->connect();
};
Worker::runAll();
} catch (\Exception $e) {
var_dump($e->getMessage());
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论