I am trying to create my own websocket with Workerman library and connect my frontend part with the server. I am using Apache2 to run it.
So, let’s see, how it looks like:
$worker = new Worker('websocket://127.0.0.1:80');
$worker->onMessage = function($connection, $data) use($worker) {
foreach($worker->connections as $clientConnection) {
$clientConnection->send('Hello World');
}
};
Worker::runAll();
let socket = new WebSocket('wss://localhost:80');
Nothing’s really special, just the way it should be done. At least as I see it.
I got no problem with opening the page with the address:
https://localhost/websocket/test.html
However, I get the error on my browser JS console:
WebSocket connection to 'wss://localhost:80/' failed
Well, ofc I tried many different ways to fix it that people recommended under similar topics.
I tried to open the page with the ‘127.0.0.1’ in address instead of ‘localhost’. The same thing. I tried to change ‘localhost’ to ‘127.0.0.1’ in address for connection in JS code – still nothing changes.
My self-signed SSL certificate works fine though the browser tells me the connection is not secure. At least I can ignore it and open the page. Still, the page can’t get connection to the websocket.
I also tried the things in Firefox, still getting what I get.
Sandro Sandro is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.