0

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?

Gergely
  • 6,879
  • 6
  • 25
  • 35

1 Answers1

0

The code works if I subscribe to the data event on standard input. That fires every time I type a new line into the standard input.

See data event documentation at Stream class.

Gergely
  • 6,879
  • 6
  • 25
  • 35