Search code examples
laravelwebsocketcentosfirewallratchet

Running Cboden Ratchet Websocket on the server


I made a chat service on my local machine and successfully ran it. This chat service uses cboden retchat library and the custom JS on frontend.

So I uploaded everything on the CENTOS server and tried to run the chat. I'm getting connection refused error. But I checked server firewall, opened ports (I changed the port from 8080 to 60000). I tried to run server on this target:

0.0.0.0:60000

and connect from client like this

SERVERIP:60000

or

DOMAIN:60000

Tried to run server also as ROOT, but I get the same error.

Is it client firewall problem? How I fix it? I found a JS package, which connects to the chat server via 80 port and there is no firewall problems. I cannot use this package, because on our server we have one hundred services ran. So I decided to use the 60000 port.

I checked the port- it's free and unblocked.

My .env file

CHAT_PROTOCOL=wss://
CHAT_ADDRESS=0.0.0.0
CHAT_PORT=60000

Client side JS

 var conn = new WebSocket(chat.protocol + SERVERIP +':'+ chat.port +'/chat');
//chat.protocol is wss://
//chat.port is 60000

Here is the problem

WebSocket connection to 'wss://SERVERIP:60000/chat' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED

Again, it was perfect on my local machine (ubuntu)


Solution

  • I found the solution after 5 month.

    My domain uses SSL connection so I should to include the CRT and KEY files by declaring the server variable.

    const server = 
         require('https').createServer({
            key: fs.readFileSync('./ssl/keys/************************.key'),
            cert: fs.readFileSync('./ssl/certs/************************.crt'),
            ca: fs.readFileSync('./ssl/certs/************************.crt'),
            requestCert: false,
            rejectUnauthorized: false
        },express);