30
30
var disconnect_count = 0;
32
32
var server = net.createServer(function(socket) {
33
socket.on('connect', function() {
34
socket.write('hello\r\n');
33
console.error('SERVER: got socket connection');
36
console.error('SERVER connect, writing');
37
socket.write('hello\r\n');
37
39
socket.on('end', function() {
40
console.error('SERVER socket end, calling end()');
41
44
socket.on('close', function(had_error) {
42
//console.log('server had_error: ' + JSON.stringify(had_error));
45
console.log('SERVER had_error: ' + JSON.stringify(had_error));
43
46
assert.equal(false, had_error);
47
50
server.listen(common.PORT, function() {
48
console.log('listening');
51
console.log('SERVER listening');
49
52
var client = net.createConnection(common.PORT);
51
54
client.setEncoding('UTF8');
53
56
client.on('connect', function() {
54
console.log('client connected.');
57
console.error('CLIENT connected', client._writableState);
57
60
client.on('data', function(chunk) {
58
61
client_recv_count += 1;
59
62
console.log('client_recv_count ' + client_recv_count);
60
63
assert.equal('hello\r\n', chunk);
64
console.error('CLIENT: calling end', client._writableState);
68
client.on('end', function() {
69
console.error('CLIENT end');
64
72
client.on('close', function(had_error) {
65
console.log('disconnect');
73
console.log('CLIENT disconnect');
66
74
assert.equal(false, had_error);
67
75
if (disconnect_count++ < N)
68
76
client.connect(common.PORT); // reconnect