Forwarding socket.io/engine.io connection to another server

给你一囗甜甜゛ 提交于 2019-12-25 09:01:56

问题


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

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.

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

Something like:

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

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


回答1:


socket.io not support something like socket.redirect

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.



来源:https://stackoverflow.com/questions/43317577/forwarding-socket-io-engine-io-connection-to-another-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!