-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.js
39 lines (26 loc) · 972 Bytes
/
client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
dgram = require('dgram');
config = require('./config.json');
for (let i = 0; i < process.argv.length; i++) {
console.log(i + ' -> ' + (process.argv[i]));
}
let udpClient = dgram.createSocket('udp4');
const HOST = config.host;
const PORT = config.port;
sendUdpMessage(process.argv[2]);
udpClient.on('message', function(message, remote){
console.log("Response from " + remote.address + ':' + remote.port +' - ' + message);
let messageStr = message.toString();
process.exit(0);
});
function sendUdpMessage(_messageString){
let updHeader = new Buffer([0,7]);
let updCommand = new Buffer(_messageString);
let udpCR = new Buffer ( [13] );
let length = updHeader.length + updCommand.length + udpCR.length;
console.log("Buffer Length: " + length);
udpMessage = Buffer.concat([updHeader, updCommand, udpCR], length);
console.log(udpMessage);
udpClient.send(udpMessage, 0, udpMessage.length, PORT, HOST, function(err, bytes){
if (err) throw err;
})
}