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 client.connect(client.address().port, common.mustCall(() => { 111cb0ef41Sopenharmony_ci client.on('message', common.mustCall(callback)); 121cb0ef41Sopenharmony_ci const buf = Buffer.alloc(1); 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ci const interval = setInterval(function() { 151cb0ef41Sopenharmony_ci client.send(buf, 0, 0, common.mustCall(callback)); 161cb0ef41Sopenharmony_ci }, 10); 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_ci function callback(firstArg) { 191cb0ef41Sopenharmony_ci // If client.send() callback, firstArg should be null. 201cb0ef41Sopenharmony_ci // If client.on('message') listener, firstArg should be a 0-length buffer. 211cb0ef41Sopenharmony_ci if (firstArg instanceof Buffer) { 221cb0ef41Sopenharmony_ci assert.strictEqual(firstArg.length, 0); 231cb0ef41Sopenharmony_ci clearInterval(interval); 241cb0ef41Sopenharmony_ci client.close(); 251cb0ef41Sopenharmony_ci } 261cb0ef41Sopenharmony_ci } 271cb0ef41Sopenharmony_ci })); 281cb0ef41Sopenharmony_ci})); 29