Reputation: 11
By now, I had working PHP Ratchet Websocket over SSL. Lately, I've set up cloudflare in my website.
After doing so, I get an error in client side: Error in connection establishment: net::ERR_SSL_PROTOCOL_ERROR
. As I check, The websocket server, in the backend, is indeed working and waiting for connections to be established.
Here is the fornt-end websocket establishment: const conn = new WebSocket('wss://xyz:8080');
And here is my websocket server set up:
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require __DIR__ . '/vendor/autoload.php';
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use dealspace_websocket\Chat;
$app = new HttpServer(
new WsServer(
new Chat()
)
);
$loop = \React\EventLoop\Factory::create();
$privateKEY = __DIR__ . '/../private/private.pem';
$publicKEY = __DIR__ . '/../private/public.pem';
$secure_websockets = new \React\Socket\Server('0.0.0.0:8080', $loop);
$secure_websockets = new \React\Socket\SecureServer($secure_websockets, $loop, [
'local_cert' => $publicKEY,
'local_pk' => $privateKEY,
'verify_peer' => false
]);
$secure_websockets_server = new \Ratchet\Server\IoServer($app, $secure_websockets, $loop);
$secure_websockets_server->run();
?>
I've also enabled errors in the server, but I don't get any when running the server.
Upvotes: 1
Views: 488
Reputation: 41
If your server use a proxy with Cloudflare, the secure Websocket can only use a HTTPS port supported by Cloudflare: https://support.cloudflare.com/hc/en-us/articles/200169156-Which-ports-will-Cloudflare-work-with-
If traffic for your domain is destined for a different port than listed above, either: Add the subdomain as a gray-clouded record via your Cloudflare DNS app, or Enable Cloudflare Spectrum.
Upvotes: 2