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.
69 lines
1.6 KiB
69 lines
1.6 KiB
14 years ago
|
var common = require('../common');
|
||
|
var assert = require('assert');
|
||
14 years ago
|
|
||
14 years ago
|
var net = require('net');
|
||
16 years ago
|
|
||
14 years ago
|
var N = 50;
|
||
16 years ago
|
var c = 0;
|
||
16 years ago
|
var client_recv_count = 0;
|
||
11 years ago
|
var client_end_count = 0;
|
||
16 years ago
|
var disconnect_count = 0;
|
||
16 years ago
|
|
||
14 years ago
|
var server = net.createServer(function(socket) {
|
||
12 years ago
|
console.error('SERVER: got socket connection');
|
||
|
socket.resume();
|
||
|
|
||
12 years ago
|
console.error('SERVER connect, writing');
|
||
|
socket.write('hello\r\n');
|
||
16 years ago
|
|
||
13 years ago
|
socket.on('end', function() {
|
||
12 years ago
|
console.error('SERVER socket end, calling end()');
|
||
15 years ago
|
socket.end();
|
||
16 years ago
|
});
|
||
16 years ago
|
|
||
13 years ago
|
socket.on('close', function(had_error) {
|
||
12 years ago
|
console.log('SERVER had_error: ' + JSON.stringify(had_error));
|
||
15 years ago
|
assert.equal(false, had_error);
|
||
16 years ago
|
});
|
||
16 years ago
|
});
|
||
15 years ago
|
|
||
14 years ago
|
server.listen(common.PORT, function() {
|
||
12 years ago
|
console.log('SERVER listening');
|
||
15 years ago
|
var client = net.createConnection(common.PORT);
|
||
16 years ago
|
|
||
14 years ago
|
client.setEncoding('UTF8');
|
||
16 years ago
|
|
||
13 years ago
|
client.on('connect', function() {
|
||
12 years ago
|
console.error('CLIENT connected', client._writableState);
|
||
15 years ago
|
});
|
||
16 years ago
|
|
||
13 years ago
|
client.on('data', function(chunk) {
|
||
15 years ago
|
client_recv_count += 1;
|
||
14 years ago
|
console.log('client_recv_count ' + client_recv_count);
|
||
|
assert.equal('hello\r\n', chunk);
|
||
12 years ago
|
console.error('CLIENT: calling end', client._writableState);
|
||
15 years ago
|
client.end();
|
||
15 years ago
|
});
|
||
16 years ago
|
|
||
12 years ago
|
client.on('end', function() {
|
||
|
console.error('CLIENT end');
|
||
11 years ago
|
client_end_count++;
|
||
12 years ago
|
});
|
||
|
|
||
13 years ago
|
client.on('close', function(had_error) {
|
||
12 years ago
|
console.log('CLIENT disconnect');
|
||
15 years ago
|
assert.equal(false, had_error);
|
||
|
if (disconnect_count++ < N)
|
||
15 years ago
|
client.connect(common.PORT); // reconnect
|
||
15 years ago
|
else
|
||
|
server.close();
|
||
|
});
|
||
16 years ago
|
});
|
||
16 years ago
|
|
||
13 years ago
|
process.on('exit', function() {
|
||
14 years ago
|
assert.equal(N + 1, disconnect_count);
|
||
|
assert.equal(N + 1, client_recv_count);
|
||
11 years ago
|
assert.equal(N + 1, client_end_count);
|
||
16 years ago
|
});
|
||
15 years ago
|
|