Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

socket.io doens't work with transports: [ 'xhr-polling' ]

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
like image 896
George Armhold Avatar asked Jan 09 '23 19:01

George Armhold


1 Answers

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' ]
};
like image 58
George Armhold Avatar answered Jan 29 '23 04:01

George Armhold