In the process of writing a project, need to use real-time data push demand, so first think of the Nodejs websocket module
Find an example of a chat room on the internet and then change it to a push for your needs
Some of the problems encountered
Return data problem: Due to Nodejs is not very familiar with the use of lazy data processing and so on the PHP back-end processing and then use Nodejs to request and then found in the process of the request back to Arraybuffer and then Baidu found that it is because of the need for JSON format conversion So I found the Json.parse () function to convert, just at the beginning of the time is very useful, but later found that the problem is the data volume is very large when the Json.parse report error
Unexpected end of JSON input
After a variety of searches, it was found at the request.
Req.on (' Data ', function (data) {
Datas = json.parse (data)
})
This process is divided into two times to execute the returned data to cut into the same size of the data, so there will be the resolution of the problem finally adopted solution
let datas = ";
Req.on (' Data ', function (data) {
Datas + = data;
})
Req.on (' End ', function () {
DATAS1 = Json.parse (datas);
})
You'll find it after you've changed.
The final summary: The problem is the reason or I do not know the Nodejs is not professional after all, so record hope will not forget to forget the calculation can also find a solution
JSON parsing is required for HTTP request return data in node. js