I wrote a UDP client to send lines from standard input to an UDP socket:
var PORT = 12000;
var HOST = '127.0.0.1';
var dgram = require('dgram');
var client = dgram.createSocket('udp4');
process.stdin.on("readable",
function() {
var chunk = process.stdin.read();
if (chunk !== null) {
client.send(chunk, PORT, HOST);
}
}
);
client.on("message",
function (message, remote) {
process.stdout.write(message);
}
);
Now, the readable
event fires on the first time but stops working afterwards.
I successfully used this on a TCP chat client and server before: I got a readable event infinitely.
What could cause the problem here?