Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
371 views
in Technique[技术] by (71.8m points)

node.js - Forwarding socket.io/engine.io connection to another server

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...