首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >传递给Ratchet\Session\SessionProvider::__construct()的参数1必须实现接口棘轮\Http\HttpServerInterface

传递给Ratchet\Session\SessionProvider::__construct()的参数1必须实现接口棘轮\Http\HttpServerInterface
EN

Stack Overflow用户
提问于 2018-11-23 11:58:03
回答 1查看 396关注 0票数 0

我试图在棘轮中使用sessionProvider,下面是我的shell脚本:

代码语言:javascript
复制
    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

EN

回答 1

Stack Overflow用户

发布于 2018-11-23 12:22:22

好的,经过长时间的搜索,我找到了解决方案,尽管棘轮文件说sessionProvider是由WsServer包装的,sessionProvider应该Wrap WsServer。

翘曲应该是这样的:

代码语言:javascript
复制
IoServer::factory(
        new HttpServer(
            new SessionProvider(
                new WsServer(
                    new Chat()
                ),
                new Handler\MemcachedSessionHandler($memcached)
            )
        ),
        6502
    );
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53446298

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档