• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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((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', common.mustCall(() => {
17  const port = client.address().port;
18  client.connect(port, common.mustCall(() => {
19    client.send([buf1, buf2], messageSent);
20  }));
21}));
22
23client.on('message', common.mustCall((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