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?