• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3
4const assert = require('assert');
5const dgram = require('dgram');
6
7const client = dgram.createSocket('udp4');
8
9client.bind(0, common.mustCall(function() {
10
11  client.on('message', common.mustCall(callback));
12
13  const port = this.address().port;
14  const buf = Buffer.alloc(1);
15
16  const interval = setInterval(function() {
17    client.send(buf, 0, 0, port, '127.0.0.1', common.mustCall(callback));
18  }, 10);
19
20  function callback(firstArg) {
21    // If client.send() callback, firstArg should be null.
22    // If client.on('message') listener, firstArg should be a 0-length buffer.
23    if (firstArg instanceof Buffer) {
24      assert.strictEqual(firstArg.length, 0);
25      clearInterval(interval);
26      client.close();
27    }
28  }
29}));
30