Pregunta

I see that PubNub say they support Socket.io - http://blog.pubnub.com/node-js-supercharged-by-pubnub/#socket.io-github

Can someone explain to me what is going on here because I thought PubNub serves the same purpose as Socket.io in that they are both an abstraction layer for realtime messaging. On their GitHub page it says it makes Socket.io faster but why are they integrating with another platform in the first place?

This seems to me like Microsoft Windows saying they now support Linux. And if you use Linux powered by Windows you'll have a faster Linux. I.e. it's a ridiculous proposition.

So what is the reason for using Socket.io with PubNub, why not just use PubNub on its own?

¿Fue útil?

Solución

Socket.IO on PubNub Network

PubNub and Socket.IO are two separate technologies, independent yet connected by the open mobile web.

PubNub Data Streaming Network

PubNub is a globally distributed Data Stream Network. Available are simple primitives that make any real-time service possible with High Reliability and Globally Distributed Data Centers.

Socket.IO Realtime Framework

Socket.IO is a framework with abstracted concepts that make network communication a little more robust with some great features and use patterns to make it easy. Consider Socket.IO is to Networking as jQuery is to HTML/JavaScript. PubNub is a TCP Socket Cloud. Socket.IO is a framework that has design patterns. Socket.IO is a nice framework on top of PubNub that gives you the some pretty great and easy-to-use design patterns. Socket.IO also has a server-component written in Node.JS which requires you to host your own cluster of servers to operate. Putting Socket.IO on PubNub removes the need to operate and run your own server cluster.

Also consider that the Socket.IO SDK for PubNub is designed for people that started with socket.io but want to migrate to PubNub. Otherwise, there is no requirement to use socket.io library if you are starting with PubNub first.

PubNub Removes the need for a server back-end so you can focus on building your apps.

Also those familiar with Socket.IO API will easily be able to port their existing JavaScript-based Socket.IO code directly onto PubNub - https://github.com/pubnub/javascript/tree/master/socket.io#how-to-use

Socket.IO Get Started Quickly

Socket.IO allows you to emit and receive custom events. Reserved Events are: connect, message, disconnect, reconnect, ping, join and leave.

Sending and receiving events.

<script src="http://cdn.pubnub.com/socket.io.min.js"></script>
<script>
(function(){
    
    // IMPORTANT: PubNub Setup with API Keys
    var pubnub_setup = {
        channel       : 'my_mobile_app',
        publish_key   : 'demo',
        subscribe_key : 'demo'
    };
    
    var socket = io.connect( 'http://pubsub.pubnub.com', pubnub_setup );
    
    socket.on( 'connect', function() {
        console.log('Connection Established! Ready to send/receive data!');
        socket.send('my message here');
        socket.send(1234567);
        socket.send([1,2,3,4,5]);
        socket.send({ apples : 'bananas' });
    } );
    
    socket.on( 'message', function(message) {
        console.log(message);
    } );
    
    socket.on( 'disconnect', function() {
        console.log('my connection dropped');
    } );
    
    // Extra event in Socket.IO provided by PubNub
    socket.on( 'reconnect', function() {
        console.log('my connection has been restored!');
    } );
    
})();
</script>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top