Ratchet: Can't connect to websocket with wss
I’m having problems adding SSL/WSS support to my app
this is my chat-server.php:
$loop = Factory::create();
$secure_websockets = new Server($loop);
$secure_websockets->listen('8080', '0.0.0.0');
$webSock = new SecureServer($secure_websockets, $loop, [
'local_cert' => 'path-to-file\server.crt',
'local_pk' => 'path-to-file\server.key',
'verify_peer' => false,
'allow_self_signed' => true
]);
$webServer = new IoServer(
new HttpServer(
new WsServer(
new Chat()
)
),
$webSock
);
$loop->run();
On client side in javascript I’m trying to connect to the websocket with this:
connection = new WebSocket('wss://ip-address:8080');
I know that ip-address is correct and port is open
On firefox console, I’m getting this error when I try to connect to the websocket:
error { target: WebSocket, isTrusted: true, srcElement: WebSocket, eventPhase: 0, bubbles: false, cancelable: false, returnValue: true, defaultPrevented: false, composed: false, timeStamp: 2213441, type: "error"}
I’m not sure how to get this working, can someone help me please?
About this issue
- Original URL
- State: open
- Created 4 years ago
- Comments: 27 (3 by maintainers)
You need to copy the TLS Certificates (Letsencrypt generated or other) into a folder that is accessible to this ssh user and provide the absolute path over there.
local_cert -> path to certificate local_pk -> path to private key
for me, self signed certificates did not work somehow, probably due to some other errors in that time, and everything worked, after trying Letsencrypt certificates and some experimentation.
the client side error is not really helping, try looking into the server-side errormessages like this:
Also, did you include “wss://” in your connection attempt?