Unable to connect to my websocket service

I’ve a problem with my web socket service

Here’s my code about the service :

<?php

namespace AppCommand;

use SymfonyComponentConsoleCommandCommand;
use SymfonyComponentConsoleInputInputInterface;
use SymfonyComponentConsoleOutputOutputInterface;
use SymfonyComponentDependencyInjectionContainerInterface;

// Include ratcher libs
use RatchetServerIoServer;
use RatchetHttpHttpServer;
use RatchetWebSocketWsServer;

use AppSocketsChat; 

class ChatServerCommand extends Command
{
    protected $container;

    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;
        parent::__construct();
    }

    protected function configure()
    {
        $this->setName('sockets:start-chat')
        ->setHelp("Starts the chat socket")
        ->setDescription("Starts the chat socket");
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $output->writeln([
          'Chat socket',// A line
          '============',// Another line
          'Starting chat, open your browser.',// Empty line
        ]);

        $server = IoServer::factory(
          new HttpServer(
            new WsServer(
              new Chat($this->container)
              )
            ),
            8080
          );
        $server->run();
    }
}

I start it on terminal with the start command :

php bin/console sockets:startchat

When I try to connect to the web socket from the browser, I’m directly disconnected

I don’t understand why…

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *