|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const common = require('../common'); |
| 4 | +const assert = require('assert'); |
| 5 | +const dgram = require('dgram'); |
| 6 | + |
| 7 | +if (common.isWindows) { |
| 8 | + // on Windows this test will fail |
| 9 | + // see https://github.com/nodejs/node/pull/5407 |
| 10 | + console.log('1..0 # Skipped: This test does not apply on Windows.'); |
| 11 | + return; |
| 12 | +} |
| 13 | + |
| 14 | +const client = dgram.createSocket('udp4'); |
| 15 | + |
| 16 | +const timer = setTimeout(function() { |
| 17 | + throw new Error('Timeout'); |
| 18 | +}, common.platformTimeout(2000)); |
| 19 | + |
| 20 | +const toSend = [new Buffer(256), new Buffer(256), new Buffer(256), 'hello']; |
| 21 | + |
| 22 | +toSend[0].fill('x'); |
| 23 | +toSend[1].fill('y'); |
| 24 | +toSend[2].fill('z'); |
| 25 | + |
| 26 | +client.on('listening', function() { |
| 27 | + client.send(toSend[0], 0, toSend[0].length, common.PORT); |
| 28 | + client.send(toSend[1], common.PORT); |
| 29 | + client.send([toSend[2]], common.PORT); |
| 30 | + client.send(toSend[3], 0, toSend[3].length, common.PORT); |
| 31 | +}); |
| 32 | + |
| 33 | +client.on('message', function(buf, info) { |
| 34 | + const expected = toSend.shift().toString(); |
| 35 | + assert.ok(buf.toString() === expected, 'message was received correctly'); |
| 36 | + |
| 37 | + if (toSend.length === 0) { |
| 38 | + client.close(); |
| 39 | + clearTimeout(timer); |
| 40 | + } |
| 41 | +}); |
| 42 | + |
| 43 | +client.bind(common.PORT); |
0 commit comments