B
B
BonBon Slick2017-10-29 14:33:06
Node.js
BonBon Slick, 2017-10-29 14:33:06

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

Node.js server:
"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);
});

client side:
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);
            });

Information about the socket will be displayed, it says that it is not connected:false

Ngninx

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';
        }

...
}

The server, as I understand it, is running, apparently an error on the client part. Firewalls turned off everything, did not help, access to port 8443 is open. Firewall settings are set to TCP inboud / outbound allowed.
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

In production and LAN, it works with http, but not with https.
And yet, https is now crossed out in the site URL.
Can you please tell me what is wrong and how to properly configure the https server on node.js, express?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
BonBon Slick, 2017-10-29
@BonBonSlick

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 question

Ask a Question

731 491 924 answers to any question