The following basic code is used to handle requests from Angular client:
/************************************************************************/
/* Launch HTTP server
/************************************************************************/
http.createServer (function(req,res) {
let data='';
req.on ('data', chunk => {
//console.log (`Data chunk: ${chunk}`);
//append chunk to data (can be multiple chuncks for 1 request)
data += chunk;
});
req.on ('end', chunks => {
//console.log (`End chunks: ${data}`);
//Do something with request
});
}).listen (8000);
The HTTP request is converted to TCP raw message and sent to 3rd party server. This external server sends back TCP response which is sent to the Angular client.
The response sent back from Node.js to the client is not according to the order of original requests. So an HTTP request in the client is getting a wrong response. The client has multiple timers each sending a request every 1 second.
I want that while a client request is handled, Node.js will not accept any other new messages.