summaryrefslogtreecommitdiff
path: root/test/parallel/test-net-write-connect-write.js
blob: b8edb0e3b39612e8e0066f06851f1888de9602ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
'use strict';
require('../common');
var assert = require('assert');
var net = require('net');

var received = '';

var server = net.createServer(function(socket) {
  socket.pipe(socket);
}).listen(0, function() {
  var conn = net.connect(this.address().port);
  conn.setEncoding('utf8');
  conn.write('before');
  conn.on('connect', function() {
    conn.write('after');
  });
  conn.on('data', function(buf) {
    received += buf;
    conn.end();
  });
  conn.on('end', function() {
    server.close();
  });
});

process.on('exit', function() {
  assert.equal(received, 'before' + 'after');
});