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.mustSucceed(function messageSent(bytes) { 10 assert.strictEqual(bytes, buf1.length + buf2.length); 11}); 12 13const buf1 = Buffer.alloc(256, 'x'); 14const buf2 = Buffer.alloc(256, 'y'); 15 16client.on('listening', function() { 17 const port = this.address().port; 18 client.send([buf1, buf2], port, messageSent); 19}); 20 21client.on('message', common.mustCall(function onMessage(buf) { 22 const expected = Buffer.concat([buf1, buf2]); 23 assert.ok(buf.equals(expected), 'message was received correctly'); 24 client.close(); 25})); 26 27client.bind(0); 28