Answer the question
In order to leave comments, you need to log in
Node.js + socket.io = ERR_CONNECTION_TIMED_OUT?
ERROR:
GET https://domain_ip:8443/socket.io/?EIO=3&transport=polling&t=Lzdux32 net::ERR_CONNECTION_TIMED_OUT
"use strict";
const express = require('express');
const app = express();
const path = require('path');
const https = require('https');
const fs = require('fs');
const sslConfigs = {
requestCert: false,
rejectUnauthorized: false,
key: fs.readFileSync('/var/www/domain/certificates/privkey.pem'), // keys directory on server
cert: fs.readFileSync('/var/www/domain/certificates/cert.pem')
};
const port = 8433;
const server = https.createServer(sslConfigs, app);
const io = require('socket.io')(server);
io.on('connection', function(socket) {
console.log('new connection');
socket.emit('message', 'This is a message from the dark side.');
});
server.listen(port, function() {
console.log('server up and running at %s port', port);
});
var socket= require("socket.io-client")('https://domain_ip:8443', { secure: true, reconnect: true, rejectUnauthorized : false });
console.log(socket);
socket.on('message', function(data) {
alert(data);
});
server{
...
#socket.io, node server
location /socket.io/{
proxy_pass https://domain_ip:8433;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
}
...
}
console.log('server up and running at %s port', port);
...
[email protected]:/var/www/domain$ node node_server.js
server up and running at 8433 port
Answer the question
In order to leave comments, you need to log in
Replace:
var socket= require("socket.io-client")('https://domain_ip:8443', { secure: true, reconnect: true, rejectUnauthorized : false });
// на
var socket= require("socket.io-client")();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question