I’m trying to create a websocket server with Node.js to run on a Windows Azure. This should be simple, but I have run into problems I haven’t been able to find solutions for anywhere.
This is my serverside code:
var ws = require('websocket.io')
, http = require('http').createServer().listen(process.env.PORT)
, server = ws.attach(http)
server.on('connection', function (socket) {
socket.on('message', function () { });
socket.on('close', function () { });
});
How do I know which port I need to connect to?
My client code is:
var ws = new WebSocket("ws://socketiopuge.azurewebsites.net");
ws.onopen = function () {
alert("opened");
};
ws.onmessage = function(msg) {
alert(msg);
};
ws.onclose = function () {
alert("closed");
};
When I run the code I get an 501 error code, and the onclode event is fired. I believe the problem is that I need to specify a port number when I create the WebSocket. Can any of you point me in the right direction? Thanks!
If you’re using the new Azure web sites, they do not support websockets yet. The same goes for all web sites hosted through IIS – node.js or not.
Your only way of currently supporting websockets in Azure is by using worker roles and supplying your own node.js executable.