mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.3 KiB
58 lines
1.3 KiB
14 years ago
|
var common = require('../common');
|
||
|
var assert = require('assert');
|
||
|
var net = require('net');
|
||
|
|
||
|
var tcpPort = common.PORT;
|
||
|
var bytesRead = 0;
|
||
|
var bytesWritten = 0;
|
||
|
var count = 0;
|
||
|
|
||
|
var tcp = net.Server(function(s) {
|
||
|
console.log('tcp server connection');
|
||
|
|
||
12 years ago
|
// trigger old mode.
|
||
|
s.resume();
|
||
|
|
||
14 years ago
|
s.on('end', function() {
|
||
|
bytesRead += s.bytesRead;
|
||
|
console.log('tcp socket disconnect #' + count);
|
||
|
});
|
||
|
});
|
||
|
|
||
12 years ago
|
tcp.listen(common.PORT, function doTest() {
|
||
|
console.error('listening');
|
||
14 years ago
|
var socket = net.createConnection(tcpPort);
|
||
|
|
||
|
socket.on('connect', function() {
|
||
|
count++;
|
||
12 years ago
|
console.error('CLIENT connect #%d', count);
|
||
14 years ago
|
|
||
13 years ago
|
socket.write('foo', function() {
|
||
12 years ago
|
console.error('CLIENT: write cb');
|
||
14 years ago
|
socket.end('bar');
|
||
|
});
|
||
|
});
|
||
|
|
||
12 years ago
|
socket.on('finish', function() {
|
||
14 years ago
|
bytesWritten += socket.bytesWritten;
|
||
12 years ago
|
console.error('CLIENT end event #%d', count);
|
||
14 years ago
|
});
|
||
|
|
||
|
socket.on('close', function() {
|
||
12 years ago
|
console.error('CLIENT close event #%d', count);
|
||
14 years ago
|
console.log('Bytes read: ' + bytesRead);
|
||
|
console.log('Bytes written: ' + bytesWritten);
|
||
|
if (count < 2) {
|
||
12 years ago
|
console.error('RECONNECTING');
|
||
14 years ago
|
socket.connect(tcpPort);
|
||
|
} else {
|
||
|
tcp.close();
|
||
13 years ago
|
}
|
||
14 years ago
|
});
|
||
|
});
|
||
|
|
||
13 years ago
|
process.on('exit', function() {
|
||
14 years ago
|
assert.equal(bytesRead, 12);
|
||
|
assert.equal(bytesWritten, 12);
|
||
|
});
|