socket.io failed-WebSocket is closed before the connection is established

I’m using a node js app

IT IS WORKING ON PORT 80 I WANT TO SHIFT THIS TO 8070

SERVER SIDE

server.js

var compression = require('compression');
var _       = require('lodash');
var express = require('express');
var server  = express();
var app     = require('http').createServer(server);
var io      = module.exports.io = require('socket.io')(app);
server.use(compression());
app.listen(8070, function(){
    console.log('listening on *:' + 8070);
});

CLIENT SIDE

<script>
var socket = io.connect('wss://myweb.io:8070/', { transports: ["websocket"] ,secure : true});            
socket.on('connect', function(data) {alert(data);});
</script>

CLIENT SIDE THAT WAS WORKIGN

<script>
var socket = io.connect('wss://myweb.io/');              
socket.on('connect', function(data) {alert(data);});
</script>

Allowed INPUT/OUTPUT From FIREWALL

sudo iptables -A INPUT -p tcp --dport 8070 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
sudo iptables -A OUTPUT -p tcp --sport 8070 -m conntrack --ctstate ESTABLISHED -j ACCEPT

Getting this error

socket.io.js:8 WebSocket connection to 'wss://myweb.io:8070/socket.io/?EIO=3&transport=websocket' failed: WebSocket is closed before the connection is established.

on changing wss to HTTP it gives this error:

socket.io.js:7 Mixed Content: The page at 'https://myweb.io/single/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://myweb.io:8070/socket.io/?EIO=3&transport=polling&t=NWJzFCW'. This request has been blocked; the content must be served over HTTPS.

on changing wss to https it give error:

socket.io.js:8 WebSocket connection to 'https://myweb.io:8070/socket.io/?EIO=3&transport=websocket' failed: WebSocket is closed before the connection is established.

Answer

trying https.createserver instead of http createserver with my cpanel keys and cert file I am able to connect with this from anywhere.

Leave a Reply

Your email address will not be published. Required fields are marked *