So I’ve been trying to figure out how to keep my program alive if this separate server that I’m running is not open yet. Right now my program’s site pulls up successfully but then the second I try to do a socket emit to the separate server (that still isn’t alive) the program shuts down immediately.
io.on("connection", (socket) => {
console.log("New Websocket connection");
socket.on("refresh", (data) => {...
});
socket.on("save", (data) => {...
});
socket.on("reset", (data) => {...
});
socket.on("incrementhomescore", (data) => {...
});
socket.on("startclock", (data) => {...
});
socket.on("stopclock", (data) => {...
});
socket.on("setclock", (data) => {...
});
socket.on("setperiod", (data) => {...
});
});
server.listen(port, () => {
console.log("Server is up on port " + port);
});
rtv_server.listen(rtv_port, function () {
console.log(
"RTV Server listening for connection requests on socket localhost:${0}",
rtv_port
);
});
// When a client requests a connection with the server, the server creates a new
// socket dedicated to that client.
rtv_server.on("connection", function (rtv_socket) {
console.log("A new connection has been established.");
g_rtv_socket = rtv_socket;
// The server can also receive data from the client by reading from its socket.
rtv_server.on("data", function (chunk) {
let data = chunk.toString();
console.log("Data received from client: ${0}", data);
});
// When the client requests to end the TCP connection with the server, the server
// ends the connection.
rtv_server.on("end", function () {
console.log("Closing connection with the client");
});
// Don't forget to catch error, for your own sake.
rtv_server.on("error", function (err) {
console.log("Error: ${0}", err);
});
});
I tried adding this but got the same result where my program just shuts down. I guess I just wondered if there was a way to loop and not allow input until my server has a good connection established.
rtv_server.on("error", function (err) {
console.log("Error: ${0}", err);
});