The meter reading system when receiving the data sent back by the meter, found that some meter sent back data is not received by the socket port, the last waiting time is exhausted, leaving a record of the instruction timeout. Because it is in the virtual test, it can be based on the TCP messages sent to the server analysis, the analysis results found that after the issuance of reading instructions within 1s, the virtual meter returned the meter reading results, and then the socket server did not receive this record.
Therefore, this test is done to test how the meter reading time and the number of meter reading affect the socket server.
Server-side:
varNET = require (' net ');varFS = require (' FS ');varServer = Net.createserver (function(socket) {Socket.on (' Data ',function(data) {data=json.parse (data); //Console.log (data.i + ': ' + data.curr); varRecord = Data.i + ': ' + Data.curr + ' \ r \ n '; Fs.appendfile ("./server log. txt", record,function(err) {if(Err) {Console.log ("Instruction Record failed:" +record); } }); varTime =NewDate (); varCurrent = Data.i + ': ' + time.getfullyear () + "-" + (Time.getmonth () + 1) + "-" + time.getdate () + "" + time.gethours () + ":" + time.getminutes () + ":" + time.getseconds () + ":" + time.getmilliseconds () + "server-side ====>> client" ; Socket.write (current); }); Socket.on (' End ',function() {Console.log (' Disconnected '); }); Socket.on (' Error ',function() {Console.log (' Disconnected '); }); Server.listen (8814,function() {Console.log (' Server start! ');});
Client:
varNET = require (' net ');varFS = require (' FS ');vari = 1;varClient = Net.connect ({port:8814},function() {setinterval (Emmit,500); //client.end (); });functionEmmit () {if(I <= 4000) {console.log (i); varTime =NewDate (); varCurrent = Time.getfullyear () + "-" + (Time.getmonth () + 1) + "-" + time.getdate () + "" + time.gethours () + ":" + time.ge Tminutes () + ":" + time.getseconds () + ":" + time.getmilliseconds () + "Client ====>> server Side" ; vardata = {}; Data.curr=Current ; DATA.I=i; Data=json.stringify (data); Client.write (data); }; I++;} Client.on (' Data ',function(data) {//Console.log (data.tostring ()); varRecord = data.tostring () + ' \ r \ n '; Fs.appendfile ("./client log. txt", record,function(err) {if(Err) {Console.log ("Instruction Record failed:" +record); } });}); Client.on (' End ',function() {Console.log (' Client Disconnected ');}); Client.on (' Error ',function() {Console.log (' Server error! ');});
A test of the net module for node. js