Reputation: 137
I have standart plan in azure websites and websockets enabled in its configuration panel. I use socket.io and node.js. Both client and server show using 'polling' as its transport instead of websocket. On the server I have these lines and they output 'polling'.
setInterval(function(){
console.log(socket.conn.transport.name);
}, 2000);
On localhost the transport used is websocket. I have already tried things proposed in other post, like this one: Socket.io connection reverts to polling, never fires the 'connection' handler, but they do resolve the problem.
Is there a way to make azure work use websocket as a transport.
Upvotes: 1
Views: 5179
Reputation: 24128
There is a offical tutorial document to help building NodeJS Webapps with socket.io and wobsocket on Azure. Your issue was answered at the section "TroubleShooting" of the doc https://azure.microsoft.com/en-us/documentation/articles/web-sites-nodejs-chat-app-socketio/#troubleshooting.
In order for Socket.IO to use WebSockets as the messaging transport, both the server and client must support WebSockets. If one or the other does not, Socket.IO will negotiate another transport, such as long polling. The default list of transports used by Socket.IO is websocket, htmlfile, xhr-polling, jsonp-polling. You can force it to only use WebSockets by adding the following code to the app.js file.
For the globol scope of app.js:
io.set('transports', ['websocket']);
Or for the connected socket:
socket.set('transports', ['websocket']);
Best Regards.
Upvotes: 2
Reputation: 613
IIS and Node need to work in conjunction in order to have websockets turned on. You will need to edit the web.config file as well as enable in the console.
Scott Hanselman has a great blog post on how to enable websockets in Azure with socket.io
http://www.hanselman.com/blog/EnablingWebsocketsForSocketioNodeAppsOnMicrosoftAzure.aspx
Upvotes: 0