Answer the question
In order to leave comments, you need to log in
How to work with morozovsk/yii2-websocket add-on?
I’m trying to figure out how Websocet works, it seemed I found a normal solution and downloaded the add-ons , I did everything according to the instructions, except for placing the Chat3WebsocketDaemonHandler class in the console / models folder and in the console / config / main.php config
'websocket' => [
'class' => 'morozovsk\yii2websocket\Connection',
'servers' => [
'chat3' => [
'class' => 'console\models\Chat3WebsocketDaemonHandler',
'pid' => '/tmp/websocket_chat.pid',
'websocket' => 'tcp://127.0.0.1:8004',
'localsocket' => 'tcp://127.0.0.1:8010',
//'master' => 'tcp://127.0.0.1:8020',
//'eventDriver' => 'event'
]
],
],
<?php
namespace console\models;
class Chat3WebsocketDaemonHandler extends \morozovsk\websocket\Daemon
{
protected function onOpen($connectionId, $info) {
//call when new client connect to server
$message ="yes";
}
protected function onClose($connectionId) {
//call when existing client close connection
}
protected function onMessage($connectionId, $data, $type) {
//call when new message from existing client
$message = "user #{$connectionId}: $data";
//send message to all client
foreach ($this->clients as $clientId => $client) {
$this->sendToClient($clientId, $message);
}
}
}
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