Roman Reiss | f29762f | 2015-05-19 11:00:06 | [diff] [blame] | 1 | 'use strict'; |
Ben Noordhuis | 9e32c2e | 2012-12-31 16:42:54 | [diff] [blame] | 2 | var common = require('../common'); |
| 3 | var assert = require('assert'); |
| 4 | var dgram = require('dgram'); |
| 5 | |
| 6 | var source = dgram.createSocket('udp4'); |
| 7 | var target = dgram.createSocket('udp4'); |
| 8 | var messages = 0; |
| 9 | |
| 10 | process.on('exit', function() { |
| 11 | assert.equal(messages, 2); |
| 12 | }); |
| 13 | |
| 14 | target.on('message', function(buf) { |
| 15 | if (buf.toString() === 'abc') ++messages; |
| 16 | if (buf.toString() === 'def') ++messages; |
| 17 | if (messages === 2) { |
| 18 | source.close(); |
| 19 | target.close(); |
| 20 | } |
| 21 | }); |
| 22 | |
| 23 | target.on('listening', function() { |
| 24 | // Second .send() call should not throw a bind error. |
| 25 | source.send(Buffer('abc'), 0, 3, common.PORT, '127.0.0.1'); |
| 26 | source.send(Buffer('def'), 0, 3, common.PORT, '127.0.0.1'); |
| 27 | }); |
| 28 | |
| 29 | target.bind(common.PORT); |