I
I
ilya19082020-12-07 10:34:44
Node.js
ilya1908, 2020-12-07 10:34:44

Need help with socket.io?

Wrote a server side script:

var fs = require('fs'),
    options = {
        key: fs.readFileSync('/etc/letsencrypt/live/*******/privkey.pem'),
        cert: fs.readFileSync('/etc/letsencrypt/live/*******/fullchain.pem')
    },
    app = require('express')(),
    server = require('https').createServer(options, app),
    io = require('socket.io')(server),
    Redis = require('ioredis'),
    redis = new Redis();


function log(log) { console.log('[APP] ' + log) }

redis.psubscribe('*', function(error, count){

});

redis.on('pmessage', function(pattern, channel, message){
    message = JSON.parse(message);
    io.emit(channel + ':' + message.event, message.data.message);
    // console.log(channel, message)
});
server.listen(8443);
log('Локальный сервер запущен на порте ' + 8443);


Client side script:
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/3.0.3/socket.io.js" ></script>

<script>
var socket = io(':8443');
</script>


When you run the script, the site encounters an error:
5fcddae38ba48958994058.png

How to fix this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
jaygen, 2020-12-09
@jaygen

Had the same problem, solved by opening the port in the firewall.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question