Problems connecting to Ratchet - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Wednesday, December 8, 2021

Problems connecting to Ratchet

I am having problems with Ratchet running on my Mac.

Chat-server.php:

<?php
use Ratchet\Server\IoServer;
use MyApp\Chat;

    require dirname(__DIR__) . '/vendor/autoload.php';

    $server = IoServer::factory(
        new Chat(),
        8080
    );

    $server->run();

Chat.php:

<?php
namespace MyApp;
require dirname(__DIR__) . '/vendor/autoload.php';
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;

class Chat implements MessageComponentInterface {
    public function onOpen(ConnectionInterface $conn) {
    }

    public function onMessage(ConnectionInterface $from, $msg) {
    }

    public function onClose(ConnectionInterface $conn) {
    }

    public function onError(ConnectionInterface $conn, \Exception $e) {
    }
}

Executing via:

php src/chat-server.php

This is definitely doing something, as the websocket on my page is going into connecting state (if I close this, I get a websocket closed message). Below is the Exception I get trying to send a message after an 8 second timeout. As you can see, the web socket is still in CONNECTING state. It seems like it is never moving to OPEN state.

I confirmed (via composer show) that cboden/ratchet is installed.

Why are my connections remaining in CONNECTING? There's stuff I've read about adding something to my.phar file. If I have a .phar file, I can't find it. I honestly don't really remember how I installed ratchet in the first place

Uncaught DOMException: Failed to execute 'send' on 'WebSocket': Still in CONNECTING state.
    at file:///usr/local/var/www/WSSTest.html:13:8
(anonymous) @ WSSTest.html:13
setTimeout (async)
(anonymous) @ WSSTest.html:12


source https://stackoverflow.com/questions/70266548/problems-connecting-to-ratchet

No comments:

Post a Comment