0

I have issue related to Socket.io connection to server. Its working fine on my local, but on dev-server it cant connect. My backend code look like this:

    var app = require('express')();
var server = require('http').Server(app);
var io = require('socket.io')(server);
var redis = require('redis');

server.listen(8080);

console.log('CONNECTED');
io.on('connection', function (socket) {
    var handshake = socket.handshake;
    console.log(handshake);
    console.log("new client connected");

    var redisClient = redis.createClient();

    redisClient.subscribe('notification');
    redisClient.subscribe('rate');

    redisClient.on("message", function(channel, message) {
        console.log("New message: " + message + ". In channel: " + channel);
        socket.emit(channel, message);
    });

    socket.on('disconnect', function() {
        redisClient.quit();
    });

});

And my client part like this:

 var socket = io.connect('http://localhost:8080');
 socket.on('notification', function (data) { console.log(data) }

The error that im facing is when socket.io client tries to send to URL "http://localhost:8080/socket.io/?EIO=3&transport=polling&t=MD_W4lE" request and its failing, with error ERR_CONNECTION_REFUSED. The node server is runing i tested and also tried to change localhost to 127.0.0.1 and ipv4 address, i didnt helped.

Grish Barseghyan
  • 51
  • 1
  • 1
  • 4

0 Answers0