问题
Currently I have deployed a node application to azure app service. My current app service plan has two core processor. And I have set nodeProcessCountPerApplication: 2 in iisnode.yml file. Now I have implemented socket.io functionality for real time update to the UI. With single process it works fine. When I use nodeProcessCountPerApplication: 2 problem starts. I am getting the following error-
{"code":1,"message":"Session ID unknown"}
I tried to solve this using socket.io-redis. Here is the code for using redis-
var io = require('socket.io')(server);
var redis = require('socket.io-redis');
io.adapter(redis({ host: 'localhost', port: 6379 }));
But getting the following error after the changes-
Error: Redis connection to localhost:6379 failed - connect EACCES 127.0.0.1:6379
at Object.exports._errnoException (util.js:1008:11)
at exports._exceptionWithHostPort (util.js:1031:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1080:14)
What am I missing. Appreciate your time.
回答1:
Per my experience, this problem happens when the client is using XHR-polling transport, and the server is in the cluster mode. So I think the best solution is use WebSocket only. To achieve that, you could follow the steps below:
- Enable WebSockets using the Azure Portal
Click the web app from the Web Apps blade, click All settings > Application settings. Under Web Sockets, click On. Then click Save. Tell Socket.IO to use WebSocket only
Replace the following code in client-endvar socket = io();
to this code:
var socket = io({transports: ['websocket']});
Hope it helps. Any further concern, please feel free to let me know.
来源:https://stackoverflow.com/questions/40112057/using-socket-io-redis-on-azure-web-service