I have acquired a shared host with a cpanel which supports nodejs. I can define a node.js app through "Setup Node.js App".
I want to make a websocket. They have opened 2088 Port for me.
This is my websocket server code:
const http = require('http');
const WebSocket = require('ws');
const server = http.createServer();
const wss = new WebSocket.Server({ server });
wss.on('connection', function connection(ws) {
ws.on('message', function incoming(message) {
console.log('received: %s', message);
});
ws.send('something');
});
server.listen(2088);
Well, I run my code and then I send this request from client to server:
socket = new WebSocket('ws://mydomain.com:2088');
socket.addEventListener('open', function (event) {
socket.send('Hello Server!');
});
socket.addEventListener('message', function (event) {
console.log('Message from server ', event.data);
});
But, I keep receiving a timeout error and I can not connect to the websocket server.
It appears that making a websocket server on a shared cpanel host that is able to listen on a specific port, is a little bit different from the usual.
I have combed through the internet and all I got on cpanel nodejs was how to build a node.js app using cpanel menus. I couldn't find any explanation on how to make a websocket on shared cpanel host. All of the sources say that it is possible to make a websocket with a nodejs which is offered on cpanel.
Now, has anyone ever had a shared host with nodejs features? And run websocket on it?
The admins who have sold the host to me, are complete idiots, know nothing about this, and can not help me...
Thanks for your help in advance.
UPDATE:
How to run Node.js and python in shared hosts differs from the way they are run in vps. According to what I found out, the phusion passenger is used in shared hosts. The problem I'm having can be solved by someone who has worked on shared hosts with Nodejs and knows about the way phusion passenger works.