4

I'm trying to test fallback to polling in socket.io, in order to verify that my app works with clients that don't support websockets for whatever reason.

I am using the very basic server/client example for Express 4. It works fine with:

// client-side
var options = {
   transports: [ 'xhr-polling', 'websocket' ]
};

var socket = io.connect('http://localhost:8080', options);
socket.on('news', function (data) {
  console.log(data);
  socket.emit('my other event', { my: 'data' });
});

However if I remove the 'websocket' from the transport, nothing happens on the client end- no error, no events, nothing. On the server side I see only:

Tue, 03 Mar 2015 16:45:49 GMT socket.io:server serve client 304
George Armhold
  • 30,824
  • 50
  • 153
  • 232

1 Answers1

10

I popped open the source and found that socket.io.js is now checking for the string polling instead of xhr-polling. So this works:

var options = {
   transports: [ 'polling' ]
};
George Armhold
  • 30,824
  • 50
  • 153
  • 232