Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Socket.io with PubNub...why?

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?

like image 783
sonicboom Avatar asked May 06 '13 07:05

sonicboom


People also ask

Is PubNub a WebSocket?

PubNub has used a variety of protocols over time, like WebSockets, MQTT, COMET, BOSH, SPDY, long polling and others, and we are exploring architectures using HTTP 2.0, and others.

Why does Socket.IO use HTTP?

Even when websockets can be used, the initial connection setup it done over HTTP. Also, a socket.io server will attach to an HTTP server so it can serve its own client code through /socket.io/socket.io.js .

Does Socket.IO use long polling?

js) and the Socket.IO client (browser, Node. js, or another programming language) is established with a WebSocket connection whenever possible, and will use HTTP long-polling as fallback.

Which is better Socket.IO or pusher?

Pusher is the category leader in delightful APIs for app developers building communication and collaboration features. On the other hand, Socket.IO is detailed as "Realtime application framework (Node. JS server)". Socket.IO enables real-time bidirectional event-based communication.


1 Answers

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>
like image 118
Stephen Blum Avatar answered Oct 11 '22 10:10

Stephen Blum