| 26 | peer2.on('connect', tryTest) |
| 27 | |
| 28 | function tryTest () { |
| 29 | if (!peer1.connected || !peer2.connected) return |
| 30 | |
| 31 | peer1.send('this is a string') |
| 32 | peer2.on('data', function (data) { |
| 33 | t.equal(typeof data, 'string', 'data is a string') |
| 34 | t.equal(data, 'this is a string', 'got correct message') |
| 35 | |
| 36 | peer2.send('this is another string') |
| 37 | peer1.on('data', function (data) { |
| 38 | t.equal(typeof data, 'string', 'data is a string') |
| 39 | t.equal(data, 'this is another string', 'got correct message') |
| 40 | |
| 41 | peer1.on('close', function () { t.pass('peer1 destroyed') }) |
| 42 | peer1.destroy() |
| 43 | peer2.on('close', function () { t.pass('peer2 destroyed') }) |
| 44 | peer2.destroy() |
| 45 | }) |
| 46 | }) |
| 47 | } |
| 48 | }) |
| 49 | |
| 50 | test('data send/receive Buffer {objectMode: true}', function (t) { |