Disabling jsonpolling for socket.io?


Since jsonpolling messes up my server I would like to disable it. I found this code on the internet to do so:

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

I put it into "sockets.on("connection"..." so it looked like this:

io.sockets.on('connection', function(socket) {
    socket.set('transports', [ 'websocket', 'htmlfile', 'xhr-polling' ],function(){
        ....code that I had directly in io.sockets.on("connection"...

However jsonpolling still seems to be active for it still messes up my server! What can I do to prevent this?

Problem courtesy of: Wingblade


When you initialize socket.io with listen, you can specify an object with config options:

var io = require('socket.io').listen(80, {
    transports: [...]

If you need to change it after load time, you can use io.set('transports', [...]).

This affects all sockets, so you only need to call it once, not for every socket you create.

Solution courtesy of: apsillers


There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.