-
Notifications
You must be signed in to change notification settings - Fork 0
/
UDPClient.js
35 lines (30 loc) · 992 Bytes
/
UDPClient.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
var PORT = 33333;
var HOST = '127.0.0.1';
const dgram = require('dgram');
const client = dgram.createSocket('udp4');
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
//var message = 'Hi marcus, you are so beautiful!';
rl.question("What is your name ? ", function (name) {
rl.question("What is the message ? ", function (msg) {
//console.log(`${name}, is a citizen of ${country}`);
var message = `${name} said ${msg}`;
client.send(message, 0, message.length, PORT, HOST, function (err, bytes) {
if (err) throw err;
console.log('\nUDP message sent to ' + HOST + ':' + PORT);
client.close();
rl.close();
});
});
});
rl.on('SIGINT', function () {
console.log("Caught interrupt signal");
//if (i_should_exit)
process.exit();
});
rl.on("close", function () {
console.log("Message sent \nBYE BYE !!");
});