Hi,
I have a question that is relative to drift/websocket-bundle and driftphp/demo package.
In order to get successfull connection between websocket server (based on Ratchet library) and websocket client (based on js code in browser) http host should match in both places.
Since in driftphp/demo ws host is set to 0.0.0.0
in both places, it's only possible to have successfull websocket connection only on local host (where both server and client should be launched).
I wanted to launch driftphp/demo on remote host and changed the affected lines, but I got an error, while running websocket container in docker.
Here is what I've changed.
In both .env
files (in root app directory and in docker-compose directory) I've added WEBSOCKET_HOST env value with my hostname.
In websocket-entrypoint.sh
file I sourced .env file and used WEBSOCKET_HOST env value as http host for websocket server.
Before:
php bin/console websocket:run 0.0.0.0:8000 --route=events --exchange=events --env=prod
After:
. .env
php bin/console websocket:run "$WEBSOCKET_HOST":8000 --route=events --exchange=events --env=prod
In Drift/views/index.twig
file I changed default ws http host value in js code.
Before:
const conn = new WebSocket('ws://0.0.0.0:{{ websocket_port }}/events');
After:
const conn = new WebSocket('ws://{{ websocket_host }}:{{ websocket_port }}/events');
In events.html
file I've also changed the default ws http host value in js code, though I guess it's not used anywhere (I've not properly searched though).
Before:
const conn = new WebSocket('ws://0.0.0.0:1234/events');
After:
const conn = new WebSocket('ws://' + window.location.hostname + ':1234/events');
Here's the error in websocket_1 container that I have in Docker:
websocket_1 | 2020-06-15T20:01:28+00:00 [debug] Notified event "console.command" to listener "Symfony\Component\HttpKernel\EventListener\DebugHandlersListener::configure".
websocket_1 |
websocket_1 | >
websocket_1 | > ReactPHP Websocket Server for DriftPHP
websocket_1 | > by Marc Morera (@mmoreram)
websocket_1 | >
websocket_1 | > Host: myHostNameHere.com
websocket_1 | > Port: 8000
websocket_1 | > Environment: prod
websocket_1 | > Debug: enabled
websocket_1 | > Routes: events
websocket_1 | > Exchanges subscribed: events
websocket_1 | >
websocket_1 |
websocket_1 | 2020-06-15T20:01:28+00:00 [error] Error thrown while running command "websocket:run 'myHostNameHere.com:8000' --route=events --exchange=events --env=prod". Message: "Could not connect to localhost:5672: Network unreachable."
websocket_1 | 2020-06-15T20:01:28+00:00 [debug] Notified event "console.error" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SuggestMissingPackageSubscriber::onConsoleError".
websocket_1 | 2020-06-15T20:01:28+00:00 [debug] Notified event "console.error" to listener "Symfony\Component\Console\EventListener\ErrorListener::onConsoleError".
websocket_1 | 2020-06-15T20:01:28+00:00 [debug] Command "websocket:run 'myHostNameHere.com:8000' --route=events --exchange=events --env=prod" exited with code "101"
websocket_1 | 2020-06-15T20:01:28+00:00 [debug] Notified event "console.terminate" to listener "Symfony\Component\Console\EventListener\ErrorListener::onConsoleTerminate".
websocket_1 |
websocket_1 | In AbstractClient.php line 235:
websocket_1 |
websocket_1 | [Bunny\Exception\ClientException (101)]
websocket_1 | Could not connect to localhost:5672: Network unreachable.
websocket_1 |
websocket_1 |
websocket_1 | Exception trace:
websocket_1 | at /var/www/vendor/bunny/bunny/src/Bunny/AbstractClient.php:235
websocket_1 | Bunny\AbstractClient->getStream() at /var/www/vendor/bunny/bunny/src/Bunny/Async/Client.php:195
websocket_1 | Bunny\Async\Client->connect() at /var/www/var/cache/prod/ContainerOM5DHun/getAmqp_EventBusClientService.php:16
websocket_1 | require() at /var/www/var/cache/prod/ContainerOM5DHun/Drift_KernelProdDebugContainer.php:161
websocket_1 | ContainerOM5DHun\Drift_KernelProdDebugContainer->load() at /var/www/var/cache/prod/ContainerOM5DHun/getAmqp_EventBusChannelService.php:13
websocket_1 | require() at /var/www/var/cache/prod/ContainerOM5DHun/Drift_KernelProdDebugContainer.php:161
websocket_1 | ContainerOM5DHun\Drift_KernelProdDebugContainer->load() at /var/www/var/cache/prod/ContainerOM5DHun/getAsyncAdapter2Service.php:25
websocket_1 | require() at /var/www/var/cache/prod/ContainerOM5DHun/Drift_KernelProdDebugContainer.php:161
websocket_1 | ContainerOM5DHun\Drift_KernelProdDebugContainer->load() at /var/www/var/cache/prod/ContainerOM5DHun/getAsyncAdapter2Service.php:12
websocket_1 | ContainerOM5DHun\Drift_KernelProdDebugContainer->{closure}() at /var/www/var/cache/prod/ContainerOM5DHun/AMQPAdapter_239a9c8.php:62
websocket_1 | Closure->__invoke() at /var/www/var/cache/prod/ContainerOM5DHun/AMQPAdapter_239a9c8.php:62
websocket_1 | AMQPAdapter_239a9c8->subscribe() at /var/www/vendor/drift/event-bus-bundle/Subscriber/EventBusSubscriber.php:64
websocket_1 | Drift\EventBus\Subscriber\EventBusSubscriber->subscribeToExchanges() at /var/www/vendor/drift/websocket-bundle/Console/RunWebsocket.php:120
websocket_1 | Drift\Websocket\Console\RunWebsocket->execute() at /var/www/vendor/symfony/console/Command/Command.php:255
websocket_1 | Symfony\Component\Console\Command\Command->run() at /var/www/vendor/symfony/console/Application.php:930
websocket_1 | Symfony\Component\Console\Application->doRunCommand() at /var/www/vendor/symfony/framework-bundle/Console/Application.php:97
websocket_1 | Symfony\Bundle\FrameworkBundle\Console\Application->doRunCommand() at /var/www/vendor/symfony/console/Application.php:264
websocket_1 | Symfony\Component\Console\Application->doRun() at /var/www/vendor/symfony/framework-bundle/Console/Application.php:83
websocket_1 | Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at /var/www/vendor/symfony/console/Application.php:140
websocket_1 | Symfony\Component\Console\Application->run() at /var/www/bin/console:45
websocket_1 |
websocket_1 | websocket:run [--route ROUTE] [--exchange EXCHANGE] [-h|--help] [-q|--quiet] [-v|vv|vvv|--verbose] [-V|--version] [--ansi] [--no-ansi] [-n|--no-interaction] [-e|--env ENV] [--no-debug] [--] <command> <path>
websocket_1 |
dockercompose_websocket_1 exited with code 101
It looks like I'm missing something or doing it wrong. Is it possible to resolve?