Answer the question
In order to leave comments, you need to log in
How to allow cross domain connection with Node.js and Socket.io server?
Good afternoon
I installed NodeJS v4.2.1 on Debian Jessie, connected the Socket.IO v1.3.7 framework to deliver data via web socket to the browser and ran into the following problem.
I have a site valyuta.com/uploads/wss.html which connects to NodeJS which is installed on a new server wss://q.investaz.net:4000
When I connect I get an error:
socket.io-1.3.7.js: 3 WebSocket connection to 'wss://q.investaz.net:4000/socket.io/?EIO=3&transport=websocket' failed: WebSocket opening handshake was canceled
and get response from server "(Opcode -1)"
Server configuration is as follows :
var fs = require('fs');
var httpsOptions = {
key: fs.readFileSync('/home/quotes/ssl/q.investaz.net.key'),
cert: fs.readFileSync('/home/quotes/ssl/q.investaz.net.chained.crt'),
ca: fs.readFileSync('/home/quotes/ssl/gd_bundle-g2-g1.crt'),
requestCert: true,
rejectUnauthorized: false
}
var app = require('https').createServer(httpsOptions, handler);
io = require('socket.io').listen(app);
app.listen(4000);
function handler (req, res) {
fs.readFile(__dirname + '/index.html',
function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading index.html');
}
res.writeHead(200);
res.end(data);
});
}
io.on('connection', function (socket) {
console.log('Server Listening: ' + 4000);
socket.emit('news', { hello: 'world' });
socket.on('my other event', function (data) {
console.log(data);
});
});
Answer the question
In order to leave comments, you need to log in
Now nothing works anywhere.
It looks like the server is down.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question