I am trying to use socket.io with pubnub. I am not able to understand how to get data on client(index.html) which I have published on the server.Below is the sample code.
my server.js
var pubnub = require("pubnub")
var p = pubnub.init({
"subscribe_key" : "xxxx",
"publish_key" : "xxxx",
"params" : {},
});
p.publish({
"message" : "foo",
"channel" : "test_channel",
});
client code - index.html
<script src="http://cdn.pubnub.com/socket.io.min.js"></script>
<script>(function(){
// IMPORTANT: PubNub Setup with Account
var pubnub_setup = {
channel : 'test_channel',
publish_key : 'xxxx',
subscribe_key : 'xxxx'
};
var socket = io.connect( 'http://pubsub.pubnub.com/', pubnub_setup );
socket.on( 'connect', function() {
console.log('Connection Established! Ready to send/receive data!');
} );
socket.on( 'message', function(message) {
console.log(message);
} );
socket.on( 'disconnect', function() {
console.log('my connection dropped');
} );
socket.on( 'reconnect', function() {
console.log('my connection has been restored!');
} );
})();</script>