Note that there are some explanatory texts on larger screens.

plurals
  1. POWebSocket can't establish a connection to the server
    primarykey
    data
    text
    <p>I try to make a simple chat page on my symfony project by WebSocket. First I used <a href="http://reactphp.org/" rel="nofollow">React-php</a> library, it perfectly works on terminal but when I try to connect it to browser I faced this error on chrome:</p> <pre><code>Uncaught Error: INVALID_STATE_ERR: DOM Exception 11 </code></pre> <p>and on firefox</p> <pre><code>Firefox can't establish a connection to the server at ws://localhost:8000/. </code></pre> <p>Next I used <a href="http://socketo.me/" rel="nofollow">Ratchet</a> library and follow the tutorial but still the same problem, work on terminal, error on browser. I use <code>telnet localhost 8000</code> on terminal and javascript on browser is</p> <pre><code>var conn = new WebSocket('ws://localhost:8000'); conn.onmessage = function(e) { console.log(e.data); }; conn.send('Hello World!'); </code></pre> <p>the server code for React</p> <pre><code>require __DIR__.'/../vendor/autoload.php'; $loop = React\EventLoop\Factory::create(); $socket = new React\Socket\Server($loop); $conns = new \SplObjectStorage(); $socket-&gt;on('connection', function ($conn) use ($conns) { $conns-&gt;attach($conn); $conn-&gt;on('data', function ($data) use ($conns, $conn) { foreach ($conns as $current) { if ($conn === $current) { continue; } $current-&gt;write($data); } }); $conn-&gt;on('end', function () use ($conns, $conn) { $conns-&gt;detach($conn); }); }); $socket-&gt;listen(8000); $loop-&gt;run(); </code></pre> <p>and server code for Ratchet</p> <pre><code>require __DIR__ . '/../vendor/autoload.php'; require __DIR__ . '/chat.php'; use Ratchet\Server\IoServer; use Ratchet\WebSocket\WsServer; use MyApp\Chat; $server = IoServer::factory( new WsServer( new Chat() ), 8000); $server-&gt;run(); </code></pre> <p>Another thing is client page url is <code>localhost/X/chat</code> and server <code>localhost/X/server</code>, I tried <code>ws://localhost:8000/X/server</code> but still doesn't work</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload