Is it possible to force Socket.io to use its Ajax fallback?

632 Views Asked by At

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

1

There are 1 best solutions below

0
On BEST ANSWER

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']
});