简体   繁体   English

为什么pubnub javascript sdk(?)选择XHR over Websocket?

[英]Why pubnub javascript sdk (?) choses XHR over Websocket?

I'm developing simple browser real-time multiplayer (2 players in a gameplay atm) game. 我正在开发简单的浏览器实时多人游戏(游戏玩法中的2个玩家)游戏。 It involves fast and frequent player moves and changes of direction, so informations must be exchanged very quickly - I decided to try websockets (would be happy to use pubnub service instead of self-hosting socket server). 它涉及快速和频繁的玩家移动和方向的变化,因此信息必须非常快速地交换 - 我决定尝试websockets(很乐意使用pubnub服务而不是自托管套接字服务器)。

My problem is, pubnub always decides to use xhr fallback instead of websockets - don't know why. 我的问题是,pubnub总是决定使用xhr fallback而不是websockets - 不知道为什么。 Are there any specific requirements that must be fulfilled to run communication via websockets? 通过websockets运行通信是否有任何特定要求? Http is obviously too slow and kills the experience. Http显然太慢了并且杀死了经验。 I'm using latest Chrome on a Mac, so browser compatibility is not an issue. 我在Mac上使用最新的Chrome,因此浏览器兼容性不是问题。

Or maybe, there is so many variables to determine communication protocol, that the question cannot be answered? 或者,可能有很多变量来确定通信协议,这个问题无法回答? And my only solution is to use self-hosted socket server? 而我唯一的解决方案是使用自托管套接字服务器?

Realtime Protocol WebSockets and XHR with PubNub 实时协议WebSockets和带有PubNub的XHR

Modern data stream networks and open source solutions start with XHR. 现代数据流网络和开源解决方案始于XHR。 For several reasons this is optimal to start with including speed. 由于多种原因,从包括速度开始这是最佳的。 Performance is dependent on the speed of light and how fast Ethernet Frames are able to be transmitted between devices on the internet. 性能取决于光速以及以太网帧能够在互联网上的设备之间传输的速度。 This is the foundation for protocol independence and the core determinator for latency and speed of messages across the internet. 这是协议独立性的基础,也是互联网上消息延迟和速度的核心决定因素。 The PubNub client SDKs, such as JavaScript, do not provide a setting to force a particular protocol. PubNub客户端SDK(例如JavaScript)不提供强制特定协议的设置。

How PubNub Works PubNub如何工作

See How PubNub Works scroll down for mouse demo. 请参阅PubNub如何工作向下滚动鼠标演示。

PubNub数据流网络

PubNub is the fastest global data stream network available today with 15 data centers world wide to support your high speed and low latency requirements. PubNub是目前最快的全球数据流网络,全球有15个数据中心,可支持您的高速和低延迟要求。 Over 1/4 billion devices connected to the PubNub data stream network experience send/receive speeds from 10ms to 100ms per message. 连接到PubNub数据流网络的超过1/4亿设备的每条消息的发送/接收速度从10毫秒到100毫秒。

What is Protocol Independence? 什么是协议独立?

The people behind the PubNub Data Stream Network believe in the Protocol Independence and the open mobile web ; PubNub数据流网络背后的人们相信协议独立和开放的移动网络 ; meaning that we will use the best protocol to get connectivity through any environment. 这意味着我们将使用最佳协议来通过任何环境获得连接。 Protocols, like WebSockets , can get tripped up by cell tower switching, double NAT environments, and even some anti-virus software or proxy boarder authorities. 协议,如WebSockets ,可以通过蜂窝塔切换,双NAT环境,甚至一些反病毒软件或代理边界管理机构来绊倒。

PubNub provides client libraries specifically so we can auto-switch the protocol and remove socket-level complexities making it easy for developers to build apps that can communicate in realtime. PubNub专门提供客户端库,因此我们可以自动切换协议并消除套接字级复杂性,使开发人员可以轻松构建可实时通信的应用程序。

PubNub has used a variety of protocols over time, like WebSockets , MQTT, COMET, BOSH, long polling and others, and we are exploring currently prototyping future designs using SPDY, HTTP 2.0, and others. 随着时间的推移,PubNub已经使用了各种协议,比如WebSockets ,MQTT,COMET,BOSH, 长轮询和其他协议,我们正在探索使用SPDY,HTTP 2.0等进行未来设计的原型设计。 The bottom line is that PubNub will work in every network environment, and has very low network bandwidth overhead, as well as low battery drain on mobile devices. 最重要的是,PubNub将在每个网络环境中运行,并且具有非常低的网络带宽开销,以及移动设备上的低电池消耗。

您还可以尝试使用WebSockets作为第一选项协议(使用XHR回退)的其他云服务,例如PusherRealtime (我工作的公司)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM