将 socket.io/engine.io 连接转发到另一台服务器 [英] Forwarding socket.io/engine.io connection to another server

查看:107
本文介绍了将 socket.io/engine.io 连接转发到另一台服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正试图找到解决 websockets 负载平衡问题的最佳方法.

We are trying to find the best approach to our load balancing issue with websockets.

Websocket 最初可以连接到任何服务器,该服务器将运行一些逻辑,然后如果需要它会将客户端重定向"到适当的服务器.

Websocket can initially connect to any server, that server will run some logic and then if needed it will "redirect" the client to appropriate server.

socket.io/engine.io 有没有办法重定向/转发连接?

Is there a way in socket.io/engine.io to redirect/forward connections?

类似于:

io.use(function(socket){
    // ... logic
    if(logic === true){
        socket.redirect("172.10.10.2:3000");
    }
});

我知道 socket.redirect 不是有效的函数,但是否有类似的东西?

I am aware of that socket.redirect is not valid function but is there something like that?

推荐答案

socket.io not support something like socket.redirect

socket.io not support something like socket.redirect

但是您可以使用 Nginx 来制作负载均衡代理并使用 socket.io-redis 为 socket.io 制作适配器并处理多个节点中的 if(logic === true){}.

But you can use Nginx to make proxy for load balance and use socket.io-redis to make adapter for socket.io and handle if(logic === true){} in multiple nodes.

这篇关于将 socket.io/engine.io 连接转发到另一台服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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