在Azure Web服务上使用socket.io-redis [英] Using socket.io-redis on azure web service

查看:50
本文介绍了在Azure Web服务上使用socket.io-redis的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,我已将节点应用程序部署到Azure应用程序服务.我当前的应用服务计划有两个核心处理器.并且我在iisnode.yml文件中设置了nodeProcessCountPerApplication:2.现在,我已经实现用于实时更新到UI的socket.io功能.通过单个过程,它可以正常工作.当我使用nodeProcessCountPerApplication时:2问题开始.我收到以下错误-

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"}

我尝试使用socket.io-redis解决此问题.这是使用redis-

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.

推荐答案

根据我的经验,当客户端使用XHR轮询传输并且服务器处于群集模式时,会发生此问题.因此,我认为最好的解决方案是仅使用WebSocket.为此,您可以按照以下步骤操作:

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:

  1. 使用Azure门户启用WebSockets
    从Web应用程序刀片中单击Web应用程序,然后单击所有设置>应用程序设置.在"Web套接字"下,单击打开".然后单击保存.
  2. 告诉Socket.IO仅使用WebSocket
    在客户端中替换以下代码
    var socket = io();

此代码:
var socket = io({transports:['websocket']});

希望它会有所帮助.如有任何其他疑问,请随时告诉我.

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

这篇关于在Azure Web服务上使用socket.io-redis的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆