S
S
Sergey Beloventsev2016-06-20 21:58:14
Yii
Sergey Beloventsev, 2016-06-20 21:58:14

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'
                    ]
                ],
            ],

this class itself was taken from you from here but slightly modified to this
<?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);
            }
        }
    }

now I'm trying to run it like this ./yii websocket/start chat3 and the reaction is not exactly zero, but this is the reaction
, and if I start writing, then like this,
I understand that this chat should not work like that, can you tell me where I was stupid.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question