Why does pubnub javascript sdk (?) Launch XHR through Websocket?

I am developing a simple real-time browser in multi-user mode (2 players in an atm game). This is due to the fast and frequent movement of players and changes in direction, so the information should be exchanged very quickly - I decided to try websockets (I would be glad to use a pubnub service instead of my own socket server).

My problem is that pubnub always decides to use xhr fallback instead of websockets - I don't know why. Are there any specific requirements that must be met in order to communicate via websites? Http is clearly too slow and kills the experience. I use the latest Chrome on Mac, so browser compatibility is not a problem.

Or maybe there are so many variables for determining the communication protocol that the question cannot be answered? And my only solution is to use a self-mounted socket server?

+7
javascript websocket real-time multiplayer pubnub
source share
2 answers

Real-Time Protocol and XHR Web Sites with PubNub

Modern data networks and open source solutions start with XHR. For several reasons, this is optimal for a start, including speed. Performance depends on the speed of light and how fast Ethernet frames can be transmitted between devices on the Internet. This is the basis for the independence of the protocol and the main determinant for the delay and speed of messages on the Internet. PubNub client SDK clients, such as JavaScript, do not provide settings for enforcing a specific protocol.

How PubNub Works

See How PubNub Works Scroll Down for a Demo of the Mouse.

PubNub Data Stream Network

PubNub is the fastest global data network available today with 15 data centers around the world to support your high speed and low latency requirements. More than 1/4 billion devices connected to the PubNub data stream network have a send / receive speed of 10 ms to 100 ms per message.

What is protocol independence?

The people behind PubNub Data Stream Network believe in Protocol Independence and an open mobile network ; that we will use the best protocol to connect to any environment. Protocols such as WebSockets can be knocked down by switching cells, a dual NAT environment, and even some antivirus programs or trusted credentials.

PubNub provides client libraries specifically so that we can automatically switch the protocol and remove complexity at the socket level, which makes it easier for developers to create applications that can communicate in real time.

PubNub uses various protocols over time, such as WebSockets , MQTT, COMET, BOSH, long polling and others, and we study prototypes of future projects using SPDY, HTTP 2.0 and others. The bottom line is that PubNub will work in every network environment and has a very low network bandwidth as well as low battery drain on mobile devices.

+3
source share

You can also try other cloud services that use WebSockets as a protocol with the first option (with XHR backup), such as Pusher and Realtime (the company I'm working on).

+1
source share

All Articles