1'use strict'; 2 3const common = require('../common'); 4const assert = require('assert'); 5const dgram = require('dgram'); 6 7const client = dgram.createSocket('udp4'); 8 9const onMessage = common.mustCall(function(err, 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 toSend = [buf1, buf2]; 18 client.send(toSend, this.address().port, common.localhostIPv4, onMessage); 19 toSend.splice(0, 2); 20}); 21 22client.on('message', common.mustCall(function onMessage(buf, info) { 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