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