Answer the question
In order to leave comments, you need to log in
How to send a message to all clients (tcp://workerman)?
To create a TCP connection, I use the WORKERMAN library. For her, let's look at an example.
use Workerman\Worker;
require_once './Workerman/Autoloader.php';
$tcp_worker = new Worker("tcp://127.0.0.1:8000");
$tcp_worker->count = 4;
$tcp_worker->onMessage = function($connection, $data) use ($tcp_worker)
{
// №1 Отправляем сообщение обратно отправителю
$connection->send($data);
// №2 Рассылаем сообщение всем клиентам
foreach ($tcp_worker->connections as $conn) {
$conn->send($data);
}
};
Worker::runAll();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question