0

I'm receiving a message on redis and I'm trying to emit it using below node code on a server:

var server = require('http').Server();
var io = require('socket.io')(server);
var Redis = require('ioredis');
var redis = new Redis();

redis.subscribe('test-channel', function() {
    console.log('I just subscribed to channel waiting for messages ...');
});

redis.on('message', function(channel, message){
    message =  JSON.parse(message);
    console.log(channel, message);    
    io.emit(channel + ':' + message.event, message.data);    
    // another test emit
    io.emit('test', 'hi!'); 
});

server.listen(3500);

And this is my client side code responsible for getting messages:

<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.3.7/socket.io.min.js"></script>

var socket = io('http://localhost:3500');

socket.on('test-channel:App\\Events\\PacketArrived', function (data){
    console.log('yes! I got it!');
    console.log(data);
});

socket.on('test', function (data){
    console.log('yes! I got it!');
    console.log(data);
} );

I get the log for redis.on('message' ... part but unfortunately, I'm not getting anything on client-side socket logs. I don't get any error messages to debug.

webi.web
  • 1
  • 2
  • Are you 100% sure that you have the same version of socket.io on client and server. Your client appears to be running 1.3.7 from the CDN. What version is your server running? Current server versions are 2.x. – jfriend00 Apr 18 '18 at 19:41
  • Yes! You're right! Thank you! I updated the client-side version to 2.1.0 and it's working fine. – webi.web Apr 18 '18 at 20:11

0 Answers0