How to use node.js to send data to the tcp server at intervals?

created tcp server, tcpserver:

var net = require("net")
var mysql = require("mysql");
var conn = mysql.createConnection({
    host:"localhost",
    user:"root",
    password:"",
    database:"gprs",
    port:3306
});
conn.connect();
net.createServer(function(socket){
    socket.on("data",function(data){
        console.log("got:",data.toString());
        var text = JSON.parse(data.toString());
        var arr = {};
        arr.tem = text.tem;
        arr.hum = text.hum;
        arr.illsum = text.illsum;

        console.log(arr);
        console.log(arr.tem);
        console.log(arr.hum);
        console.log(arr.illsum);
        //mysql
        conn.query("INSERT INTO gprsdata SET ?", arr, function(error,result,fields){
            if (error) throw error;
        });
    });
    socket.on(
        "end",function(data){
        console.log("end");
    });
    socket.write("Ready to receive your message!")
}).listen(4001);

tcpclient.js: created

const net = require("net");
const client = net.connect({port:4001},()=> {
    console.log("connected to server!");
client.write("{\"tem\":\"20\",\"hum\":\"30\",\"illsum\":\"473\"}");
});
client.on("data",(data) => {
    console.log(data.toString());
client.end();
});
client.on("end",() => {
    console.log("disconnected from server");
});
Mar.13,2021

use timer


Server results
clipboard.png

clipboard.png

Server code

  

Yes, thank you for taking the time to answer my questions.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e98d1d-474d0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e98d1d-474d0.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?