简体   繁体   中英

Argument 1 passed to Ratchet\Session\SessionProvider::__construct() must implement interface Ratchet\Http\HttpServerInterface

I'm trying to use sessionProvider in Ratchet, the following is my shell script:

    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();
    }
}

an error occur say:

Argument 1 passed to Ratchet\\Session\\SessionProvider::__construct() must implement interface Ratchet\\Http\\HttpServerInterface, instance of App\\Http\\Controllers\\WebSockets\\Chat given

how to solve this issue !

my Chat class implement MessageComponentInterface .

ok after a long search i found the solution, even though ratchet document says the sessionProvider wrapped by WsServer, sessionProvider should Wrap the WsServer.

the warps should be like this instead:

IoServer::factory(
        new HttpServer(
            new SessionProvider(
                new WsServer(
                    new Chat()
                ),
                new Handler\MemcachedSessionHandler($memcached)
            )
        ),
        6502
    );

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM