w*s 发帖数: 7227 | 1 my flow is like this,
browser<-->node<-->backend server doing calculation
node and backend uses socket to chat.
from browser there're start/stop buttons to let backend start/stop the
calculation.
before node asks backend to start/stop, it must query to see if backend is
alive first.
my code is like this
app.get('/stopCmd', function(req, res)
{
socketToBackendServer.write("status", function() {
console.log("Sending:", 'Node asking for STATUS');
});
socketToBackendServer.on("data", function() {
if(status is ok) // pseudo code
{
socketToBackendServer.write("stop", function() {
console.log("Sending:", 'Node sending STOP');
});
} else {
console.log("backend server is NOT ready");
}
});
});
app.get('/startCmd', function(req, res)
{
// do similar things as stopCmd
}
if using the same browser, if i go crazy clicking start/stop... for the "
stopCmd", how to make sure when it queries "status", the response is caught
by its function, not "startCmd"'s ?
it's this line
socketToBackendServer.on("data", function()
Thank you again ! |
|