Code Monkey home page Code Monkey logo

Comments (6)

sy-records avatar sy-records commented on May 20, 2024

现在的就是一一对应的,没使用channel。

from mqtt.

Dmcz avatar Dmcz commented on May 20, 2024

那也就会导致,监听消息之后。 没法再订阅,发布等操作了。

from mqtt.

sy-records avatar sy-records commented on May 20, 2024

这看你代码怎么写了

from mqtt.

Dmcz avatar Dmcz commented on May 20, 2024
\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 简单的实现了一下。
如果大佬有时间 看能不能 提供个例子参考。

from mqtt.

sy-records avatar sy-records commented on May 20, 2024

你用channel也行的,看下这两个吧 hyperf/hyperf#3260 hyperf/hyperf#3026

from mqtt.

Dmcz avatar Dmcz commented on May 20, 2024

ok, thx.

from mqtt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.