2016-01-29 14:18:27 +01:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
const dgram = require('dgram');
|
|
|
|
|
|
|
|
const client = dgram.createSocket('udp4');
|
|
|
|
|
2016-05-17 12:36:54 +02:00
|
|
|
const messageSent = common.mustCall(function messageSent(err, bytes) {
|
2016-01-29 14:18:27 +01:00
|
|
|
assert.equal(bytes, buf1.length + buf2.length);
|
|
|
|
});
|
|
|
|
|
2016-01-25 15:00:06 -08:00
|
|
|
const buf1 = Buffer.alloc(256, 'x');
|
|
|
|
const buf2 = Buffer.alloc(256, 'y');
|
2016-01-29 14:18:27 +01:00
|
|
|
|
|
|
|
client.on('listening', function() {
|
2016-05-29 03:06:56 -04:00
|
|
|
const port = this.address().port;
|
|
|
|
client.send([buf1, buf2], port, common.localhostIPv4, messageSent);
|
2016-01-29 14:18:27 +01:00
|
|
|
});
|
|
|
|
|
2016-05-17 12:36:54 +02:00
|
|
|
client.on('message', common.mustCall(function onMessage(buf, info) {
|
2016-01-29 14:18:27 +01:00
|
|
|
const expected = Buffer.concat([buf1, buf2]);
|
|
|
|
assert.ok(buf.equals(expected), 'message was received correctly');
|
|
|
|
client.close();
|
2016-05-17 12:36:54 +02:00
|
|
|
}));
|
2016-01-29 14:18:27 +01:00
|
|
|
|
2016-05-29 03:06:56 -04:00
|
|
|
client.bind(0);
|