mqtt icon indicating copy to clipboard operation
mqtt copied to clipboard

How to disconnect inside a Chat client?

Open rcpinheiro opened this issue 4 years ago • 1 comments

I've altered the chatroom example to let the user exit the chatroom:

        $console = new TcpConnection(STDIN);
        $console->onMessage = function($console, $message) use ($mqtt){
            $message=trim($message);
            if ($message=="exit") {
                $mqtt->disconnect();
                die;
            } else {
                $mqtt->publish('testRoom', $message);
            }
        };

When the user enters "exit" I want the worker to stop but it reconnects always. I've tried using "$mqtt->doNotReconnect=true;" but it doesn't work. Anyone knows how to do this?

rcpinheiro avatar Nov 18 '19 19:11 rcpinheiro

Maybe you can use $mqtt->close() to close connection. @rcpinheiro

mouyong avatar Jul 18 '22 07:07 mouyong