Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

138
Visualizações
Controlling multiple servers in Socket IO

I am currently developing a local website where people can scan a QR-Code at their table, for them to enter in the twitch channel name they want to watch on the screen beside them, in a website that opens.

As I am quite new to programming this was a tough one, but I found and learned SocketIO which made me able to scale up the project to each screen we have.

But the problem is now that I can't Control/override the different servers on different ports.

The servers are set up like this:
10.10.30.36/Client: 4000
10.10.30.36/Screen : 4000

10.10.30.36/Client: 4001
10.10.30.36/Screen : 4001

So 4000 can interact, but 4000 can't interact with 4001. I'm trying to make an admin page that can override all the screens with.

I have tried different solution to this problem for 35 hours now and have not found one yet.

My code is set up like this: (I have tried running the different servers using an array of the ports and a forEach statement instead, but I found this approach to give me a tiny bit more control. )

var express = require("express");
var socket = require("socket.io");
var app = express();

app.use(express.static(__dirname + '/public'));
app.use("/screen", express.static(__dirname + '/screen'));
app.use("/admin", express.static(__dirname + '/admin'));

function RUN() {
    function RUN4000() {
        var port2 = socket(port= app.listen(4000));
        RUN2(port2)
    }
    function RUN4001() {    
        var port2 = socket(port= app.listen(4001));
        RUN2(port2)
    }
    RUN4000();
    RUN4001();

    function RUN2(port2) {
        port2.on("connection", function test(socket){
            console.log("Made socket connection")

            
            ///If the Client-page sends a Twitchname, run Run(Twitch Name)//
            socket.on("Twitch", function(data){
                run(data)
            });
        
        });        

        function run(data){
            console.log("Recived Message");    
            port2.sockets.emit("restart browser", data); 
            //Sends the Twitch Name to the Screen-page
            setTimeout(function(){ port2.sockets.emit("Twitch", data); }, 1000);
        }
    }
}
RUN()

I have tried stopping the serves with a kind of if (response from adminpage == true) { return false; } else { RUN4001; RUN 4000; } statement, but the servers won't stop even if the statement is true. I have also tried an approach where the admin page was on port 5000, separated, and then passed the Twitch name down the functions to RUN2, but it did not work either.

Have been stuck on this step for a long time now, does anybody have any ideas on how I can control the different ports/servers from one adminpage?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda