roost/node/test_sender/index.js

33 lines
859 B
JavaScript

const dgram = require("dgram");
const fs = require("fs");
const path = require("path");
const cellularChunking = require("./../cellularChunking");
const messageParser = require("./../messages");
const socket = dgram.createSocket("udp4");
function send_next_line(i, theLines) {
console.log(`sending line ${i} of ${theLines.length}`);
if (theLines.length > i) {
socket.send(
Buffer.from(theLines[i], "hex"),
57321,
"127.0.0.1",
function (err) {
setTimeout(send_next_line, 100, i + 1, theLines);
//send_next_line(i + 1, theLines)
},
);
} else {
process.exit();
}
}
// open the file with the messages and then send them
try {
const fileData = fs.readFileSync("./data/test_data.txt", "utf8");
const theLines = fileData.split("\n");
let i = 0;
send_next_line(i, theLines);
} catch (e) {}