1

I'm making an Ionic app that needs real time data (a few seconds delay is OK) and I want to use Ajax (with or without long polling) because I may not have the resources to use websockets. However, I want to make it easily upgradable to websockets. Since Socket.io uses Ajax as a fallback, is there a way to force it to use Ajax? This way, I can easily upgrade to websockets if I have the resources.

P.s. just confirming, a server can usually support more clients using Ajax than websockets right? (assume 5-10 seconds per Ajax request).

Leo Jiang
  • 24,497
  • 49
  • 154
  • 284
  • Also, to answer your P.S, see the answer to this: http://stackoverflow.com/questions/4852702/do-html-websockets-maintain-an-open-connection-for-each-client-does-this-scale – Patrick Roberts Jun 10 '15 at 20:15

1 Answers1

2

Assuming your backend is node.js, var socket = require('socket.io')(); and your socket.io version is 0.x:

socket.set('transports', [
  'xhr-polling'
]);

Otherwise the new syntax for socket.io 1.x is:

var socket = require('socket.io')({
  'transports': ['xhr-polling']
});
Patrick Roberts
  • 49,224
  • 10
  • 102
  • 153