I'm running VVV (Vagrant) with socket-io-redis. This seems to be working, the messages are sending to Redis.
I test with SUBSCRIBE socket.io#/#
which is logging a bunch of messages for testing.
This is an example of the response I'm seeing in terminal -
1) "message"
2) "socket.io#/#"
3) "\x93\xa7emitter\x83\xa4type\x02\xa4data\x92\xa4time\xb82016-04-03T22:17:21.478Z\xa3nsp\xa1/\x82\xa5rooms\x90\xa5flags\x80"
Node JS -
var redis = require('socket.io-redis');
var io = require('socket.io')(3000);
io.adapter(redis({ host: '192.168.50.4', port: 6379 }));
// Handle opened socket connections
io.on('connection', function(socket) {
console.log( 'Connection' );
});
var io = require('socket.io-emitter')({ host: '192.168.50.4', port: 6379 });
setInterval(function(){
io.emit('time', new Date);
}, 5000);
Client -
( function( window, undefined ) {
'use strict';
var socket = io( '192.168.50.4:3000', {transports:['websocket']} );
socket.on( 'time', function() {
console.log( 'Received time' );
});
socket.on( 'connect', function() {
console.log( 'Connected' );
console.log( socket );
});
} )( this );
When I run the Node app I see the message Connection
, in the console of my browser I see the message Connected
(then the socket for debug).
I cant' see anything obviously wrong, the client connects and the emitter seems to be working. But nothing emitted is ever received by the client.
Am I missing something? The IPs are not local host due to running Vagrant.
Any advice appreciated. Thanks!
EDIT:
Quick update, I can emit without using socket.io-emitter
, however it doesn't go through Redis. When I use emitter, it goes through Redis correctly, as mentioned above.
It seems as though my client isn't receiving the messages from Redis, even though the ports are open.
Here's what I try -
socket.emit( 'new_post', 'Nope' );
var io = require('socket.io-emitter')({ host: '192.168.50.4', port: 6379 });
io.emit( 'new_post', 'Yep' );
In my browser I see Nope
but nothing else. I then monitor
Redis and see the following -
"publish" "socket.io#/#" "\x93\xa7emitter\x83\xa4type\x02\xa4data\x92\xa8new_post\xa3Yep\xa3nsp\xa1/\x82\xa5rooms\x90\xa5flags\x90"
My server also doesn't see messages when using Redis, I test with -
socket.on( 'new_post', function( msg ){
socket.emit( 'new_post', msg );
});