-
-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[QUESTION] 关于协程客户端 #37
Labels
question
Further information is requested
Comments
现在的就是一一对应的,没使用channel。 |
那也就会导致,监听消息之后。 没法再订阅,发布等操作了。 |
这看你代码怎么写了 |
\Hyperf\Utils\Coroutine::create(function() use($timeSincePing) {
try {
$client = $this->client();
while($this->running){
$buffer = $client->recv();
if ($buffer && $buffer !== true) {
$timeSincePing = time();
$this->onMessage($buffer);
}
if ($timeSincePing <= (time() - $client->getConfig()->getKeepAlive())) {
$buffer = $client->ping();
if ($buffer) {
$this->write('ping success');
$timeSincePing = time();
} else {
$client->close();
break;
}
}
}
} catch (\Throwable $th) {
$this->write('recv coroutine has error: ' . $th->getMessage());
}
}); 我目前只是再协程中 while true 简单的实现了一下。 |
你用channel也行的,看下这两个吧 hyperf/hyperf#3260 hyperf/hyperf#3026 |
ok, thx. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
SWOOLE不能有多个协程对一个 客户端 进行读 / 写操作。所以将读和写分成了两个协程, 通过channel来做通讯。
但这样似乎对mqtt ack 的处理不太友好。
想问问大佬们是咋处理的。
The text was updated successfully, but these errors were encountered: