Answer the question
In order to leave comments, you need to log in
Problems with WebSocket when creating a chat on yii2?
I create a chat on yii2 via WebSocket, according to this tutorial , the problem is as follows, when loading the page, an error occurs:
Class 'consik\yii2websocket\WebSocketServer' not found.
"autoload": {
"psr-4": {
"consik\\yii2websocket\\": ""
}
},
Answer the question
In order to leave comments, you need to log in
If you are using a ready-made theme (basic in your case), you don’t need to climb into the composer without knowledge. Nothing needs to be added there.
You need to create a "daemon" with its logic:
<?php
namespace app\daemons;
use consik\yii2websocket\events\WSClientMessageEvent;
use consik\yii2websocket\WebSocketServer;
class EchoServer extends WebSocketServer
{
public function init()
{
parent::init();
$this->on(self::EVENT_CLIENT_MESSAGE, function (WSClientMessageEvent $e) {
$e->client->send( $e->message );
});
}
}
<?php
namespace app\commands;
use app\daemons\EchoServer;
use yii\console\Controller;
class ServerController extends Controller
{
public function actionStart($port = null)
{
$server = new EchoServer();
if ($port) {
$server->port = $port;
}
$server->start();
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question