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 client.connect(client.address().port, common.mustCall(() => { 11 client.on('message', common.mustCall(callback)); 12 const buf = Buffer.alloc(1); 13 14 const interval = setInterval(function() { 15 client.send(buf, 0, 0, common.mustCall(callback)); 16 }, 10); 17 18 function callback(firstArg) { 19 // If client.send() callback, firstArg should be null. 20 // If client.on('message') listener, firstArg should be a 0-length buffer. 21 if (firstArg instanceof Buffer) { 22 assert.strictEqual(firstArg.length, 0); 23 clearInterval(interval); 24 client.close(); 25 } 26 } 27 })); 28})); 29