1'use strict'; 2 3const common = require('../common'); 4const assert = require('assert'); 5const dgram = require('dgram'); 6 7const client = dgram.createSocket('udp4'); 8 9const messageSent = common.mustCall(function messageSent(err, bytes) { 10 assert.ifError(err); 11 assert.strictEqual(bytes, buf1.length + buf2.length); 12}); 13 14const buf1 = Buffer.alloc(256, 'x'); 15const buf2 = Buffer.alloc(256, 'y'); 16 17client.on('listening', function() { 18 const port = this.address().port; 19 client.send([buf1, buf2], port, messageSent); 20}); 21 22client.on('message', common.mustCall(function onMessage(buf) { 23 const expected = Buffer.concat([buf1, buf2]); 24 assert.ok(buf.equals(expected), 'message was received correctly'); 25 client.close(); 26})); 27 28client.bind(0); 29