11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_ciconst assert = require('assert'); 51cb0ef41Sopenharmony_ciconst dgram = require('dgram'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst client = dgram.createSocket('udp4'); 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ciclient.bind(0, common.mustCall(function() { 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ci client.on('message', common.mustCall(callback)); 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ci const port = this.address().port; 141cb0ef41Sopenharmony_ci const buf = Buffer.alloc(1); 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci const interval = setInterval(function() { 171cb0ef41Sopenharmony_ci client.send(buf, 0, 0, port, '127.0.0.1', common.mustCall(callback)); 181cb0ef41Sopenharmony_ci }, 10); 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_ci function callback(firstArg) { 211cb0ef41Sopenharmony_ci // If client.send() callback, firstArg should be null. 221cb0ef41Sopenharmony_ci // If client.on('message') listener, firstArg should be a 0-length buffer. 231cb0ef41Sopenharmony_ci if (firstArg instanceof Buffer) { 241cb0ef41Sopenharmony_ci assert.strictEqual(firstArg.length, 0); 251cb0ef41Sopenharmony_ci clearInterval(interval); 261cb0ef41Sopenharmony_ci client.close(); 271cb0ef41Sopenharmony_ci } 281cb0ef41Sopenharmony_ci } 291cb0ef41Sopenharmony_ci})); 30