Socket.io 和 PubNub ......为什么? [英] Socket.io with PubNub...why?

查看:44
本文介绍了Socket.io 和 PubNub ......为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到 PubNub 说他们支持 Socket.io - http://blog.pubnub.com/node-js-supercharged-by-pubnub/#socket.io-github

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

有人可以向我解释这里发生了什么,因为我认为 PubNub 与 Socket.io 的用途相同,因为它们都是用于实时消息传递的抽象层.在他们的 GitHub 页面上,它说它使 Socket.io 更快,但为什么他们首先要与另一个平台集成?

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?

在我看来,这就像 Microsoft Windows 说他们现在支持 Linux.如果您使用由 Windows 提供支持的 Linux,您将拥有更快的 Linux.IE.这是一个荒谬的提议.

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.

那么使用 Socket.io 和 PubNub 的原因是什么,为什么不单独使用 PubNub?

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

推荐答案

Socket.IO on PubNub Network

PubNub 和 Socket.IO 是两种独立的技术,独立但通过开放的移动网络连接.

Socket.IO on PubNub Network

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

PubNub 是一个全球分布数据流网络.可用的简单原语通过高可靠性全球分布式数据中心使任何实时服务成为可能.

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 是一个具有抽象概念的框架,它通过一些强大的功能使网络通信更加健壮,并使用模式使其变得容易.考虑 Socket.IO 之于网络就像 jQuery 之于 HTML/JavaScript.PubNub 是一个 TCP 套接字云.Socket.IO 是一个具有设计模式的框架.Socket.IO 是 PubNub 之上的一个很好的框架,它为您提供了一些非常棒且易于使用的设计模式.Socket.IO 还有一个用 Node.JS 编写的服务器组件,它需要您托管自己的服务器集群才能运行.将 Socket.IO 放在 PubNub 上,无需操作和运行您自己的服务器集群.

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.

还要考虑,适用于 PubNub 的 Socket.IO SDK 是为刚开始使用 socket.io 但又想迁移到 PubNub 的人设计的.否则,如果您先从 PubNub 开始,则不需要使用 socket.io 库.

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 不再需要服务器后端,因此您可以专注于构建应用程序.

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

那些熟悉 Socket.IO API 的人也可以很容易地将他们现有的基于 JavaScript 的 Socket.IO 代码直接移植到 PubNub - https://github.com/pubnub/javascript/tree/master/socket.io#how-to-use

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 快速入门

Socket.IO 允许您发出和接收自定义事件.保留事件有:连接、消息、断开连接、重新连接、ping、加入和离开.

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.

<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>

这篇关于Socket.io 和 PubNub ......为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆