我试图在棘轮中使用sessionProvider,下面是我的shell脚本:
namespace App\Console\Commands;
use Ratchet\Session\SessionProvider;
use Illuminate\Console\Command;
use Ratchet\Server\IoServer;
use App\Http\Controllers\WebSockets\Chat;
use Ratchet\WebSocket\WsServer;
use Ratchet\Http\HttpServer;
use Symfony\Component\HttpFoundation\Session\Storage\Handler;
class ChatShell extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'command:chat';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$memcached = new \Memcached();
$server = IoServer::factory(
new HttpServer(
new WsServer(
new SessionProvider(
new Chat(),
new Handler\MemcachedSessionHandler($memcached)
)
)
),
6502
);
$server->run();
}
}一个错误发生,例如:
传递给Ratchet\Session\SessionProvider::__construct()的参数1必须实现接口棘轮\Http\HttpServerInterface,并给出App\Http\Controller\WebSocket\Chat实例
如何解决这个问题!
我的聊天类实现了MessageComponentInterface。
发布于 2018-11-23 12:22:22
好的,经过长时间的搜索,我找到了解决方案,尽管棘轮文件说sessionProvider是由WsServer包装的,sessionProvider应该Wrap WsServer。
翘曲应该是这样的:
IoServer::factory(
new HttpServer(
new SessionProvider(
new WsServer(
new Chat()
),
new Handler\MemcachedSessionHandler($memcached)
)
),
6502
);https://stackoverflow.com/questions/53446298
复制相似问题