2

I've got a socket.io v0.9.17 node js app deployed on azure (which I've tested locally with two clients and it works fine) with the following code:

var util = require("util");
var port = process.env.PORT || 1337;
var app = require("http").createServer(function (req, res) {
    res.writeHead(200, { "Content-Type": "text/plain" });
    res.end("Socket.io application");
}).listen(port);

var io = require('socket.io').listen(app);

io.configure(function () {
    io.set("transports", ["websocket"]);
});

io.sockets.on('connection', function (client) { ... }

I try to connect to it through a socket.io-java-client with:

// Have tested with different ports
socket.connect("http://myapp.azurewebsites.net:1337/", this);

This give me error on the client:

Error while handshaking... Operation timed out

Logs on the server:

debug: websocket writing 1::
debug: setting request GET /socket.io/1/websocket/SFePun_Ug5ycS5EVIrSO
debug: set heartbeat interval for client SFePun_Ug5ycS5EVIrSO
debug: discarding transport
debug: cleared heartbeat interval for client SFePun_Ug5ycS5EVIrSO
debug: setting request GET /socket.io/1/websocket/SFePun_Ug5ycS5EVIrSO
debug: set heartbeat interval for client SFePun_Ug5ycS5EVIrSO
debug: discarding transport
debug: cleared heartbeat interval for client SFePun_Ug5ycS5EVIrSO
debug: setting request GET /socket.io/1/websocket/SFePun_Ug5ycS5EVIrSO
debug: set heartbeat interval for client SFePun_Ug5ycS5EVIrSO
debug: discarding transport
(repeated a couple of times)
...
IIS Detailed Error - 503.13 - Number of active WebSocket requests has reached the maximum concurrent WebSocket requests allowed.

socket.connect("http://myapp.azurewebsites.net/", this);

Which shouldn't happen if I connect one client.

Any ideas how to fix this?

EDIT: Tried to change from transport websocket to xhr-polling. This doesn't give me the HTTP 503.13 error and establishes connection to the server but it works poorly.

codingIsFun
  • 91
  • 1
  • 10

2 Answers2

2

As I known, you need to enable the Web sockets options in the tab Application settings on Azure portal or configure the web.config file for adding the content <webSocket enabled="true" /> if you want to use the websocket feature.

As reference, please see below.

Figure 1. Enable the Web sockets on Azure portal enter image description here

Refering to the wiki page Using a custom web.config for Node apps, the websocket feature is default disabled.

As @ArneRie said, Azure webapps only listen on the ports 80 & 443, please see https://github.com/projectkudu/kudu/wiki/Azure-Web-App-sandbox#network-endpoint-listening.

And for the limits of websockets per app service instance for different tier, please see https://azure.microsoft.com/en-us/documentation/articles/azure-subscription-service-limits/#app-service-limits.

enter image description here enter image description here

So I think the first step is that make sure the websocket feature enabled, then try to establish the websocket connection with the http protocol and port 80 via the socket.io-java-client.

Hope it helps. Any concern, please feel free to let me know.

Peter Pan
  • 23,476
  • 4
  • 25
  • 43
  • I've actually done all of the above, and I have the standard plan. The port seem to be 80 when I use process.env.PORT and I still get the http 503.13 error. – codingIsFun May 16 '16 at 14:05
  • @codingIsFun Please refer to the section `Node.js Basic Chat Example` of the [blog](https://azure.microsoft.com/en-us/blog/introduction-to-websockets-on-windows-azure-web-sites/) and try to use the `https` protocol for the client. – Peter Pan May 19 '16 at 07:11
  • thanks for mentioning that only ports 80 and 443 are open – Cassio Sep 13 '18 at 09:48
1

Azure maps always to port 80/443 for your Node.JS Applications.

var port = process.env.PORT || 1337;

Your app is listening on port 80/443 with this piece of code.

I dont know on what kind of Hosting-Plan you are running, but when you have the Free tier, connections are very limited (5?).

May be you are running in this bug, with TCP Connections not closed after timeout: Node.js - Socket.io - Issue with "maximum concurrent connections"

Community
  • 1
  • 1
opHASnoNAME
  • 20,224
  • 26
  • 98
  • 143
  • I've got the standard-hosting-plan so it should work for one client. 80 gives me the same errors as the other ports. 443 gives me exception connection reset. None of these seem to work locally though. It says: warn - error raised: Error: listen EACCES 0.0.0.0:443 – codingIsFun May 13 '16 at 12:56
  • I've also seen that post, but the error occur with only one client connected and standard plan should give unlimited or 350 concurrent connections. – codingIsFun May 13 '16 at 13:03