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(common.mustSucceed((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', common.mustCall(function() {
17  const toSend = [buf1, buf2];
18  client.connect(client.address().port, common.mustCall(() => {
19    client.send(toSend, onMessage);
20  }));
21}));
22
23client.on('message', common.mustCall(function onMessage(buf, info) {
24  const expected = Buffer.concat([buf1, buf2]);
25  assert.ok(buf.equals(expected), 'message was received correctly');
26  client.close();
27}));
28
29client.bind(0);
30