2009-10-31 19:02:30 +01:00
|
|
|
process.mixin(require("./common"));
|
|
|
|
tcp = require("tcp");
|
2009-06-08 19:10:23 +02:00
|
|
|
var N = 50;
|
2009-05-19 21:53:26 +02:00
|
|
|
var port = 8921;
|
|
|
|
|
2009-08-14 12:51:46 +02:00
|
|
|
var c = 0;
|
2009-06-08 19:10:23 +02:00
|
|
|
var client_recv_count = 0;
|
2009-08-14 12:51:46 +02:00
|
|
|
var disconnect_count = 0;
|
2009-06-08 19:10:23 +02:00
|
|
|
|
2009-09-28 16:08:09 +02:00
|
|
|
var server = tcp.createServer(function (socket) {
|
2009-08-26 18:22:00 +02:00
|
|
|
socket.addListener("connect", function () {
|
|
|
|
socket.send("hello\r\n");
|
2009-06-27 20:40:43 +02:00
|
|
|
});
|
2009-05-19 21:53:26 +02:00
|
|
|
|
2009-08-26 18:22:00 +02:00
|
|
|
socket.addListener("eof", function () {
|
|
|
|
socket.close();
|
2009-06-27 20:40:43 +02:00
|
|
|
});
|
2009-05-19 21:53:26 +02:00
|
|
|
|
2009-08-26 18:22:00 +02:00
|
|
|
socket.addListener("close", function (had_error) {
|
|
|
|
//puts("server had_error: " + JSON.stringify(had_error));
|
2009-11-28 18:26:59 +01:00
|
|
|
assert.equal(false, had_error);
|
2009-06-27 20:40:43 +02:00
|
|
|
});
|
2009-08-26 18:22:00 +02:00
|
|
|
});
|
|
|
|
server.listen(port);
|
|
|
|
|
2009-09-28 16:08:09 +02:00
|
|
|
var client = tcp.createConnection(port);
|
2009-08-26 18:22:00 +02:00
|
|
|
|
|
|
|
client.setEncoding("UTF8");
|
|
|
|
|
|
|
|
client.addListener("connect", function () {
|
|
|
|
puts("client connected.");
|
|
|
|
});
|
|
|
|
|
|
|
|
client.addListener("receive", function (chunk) {
|
|
|
|
client_recv_count += 1;
|
|
|
|
puts("client_recv_count " + client_recv_count);
|
2009-11-28 18:26:59 +01:00
|
|
|
assert.equal("hello\r\n", chunk);
|
2009-08-26 18:22:00 +02:00
|
|
|
client.close();
|
|
|
|
});
|
|
|
|
|
|
|
|
client.addListener("close", function (had_error) {
|
|
|
|
puts("disconnect");
|
2009-11-28 18:26:59 +01:00
|
|
|
assert.equal(false, had_error);
|
2009-08-26 22:03:19 +02:00
|
|
|
if (disconnect_count++ < N)
|
2009-08-26 18:22:00 +02:00
|
|
|
client.connect(port); // reconnect
|
|
|
|
else
|
|
|
|
server.close();
|
|
|
|
});
|
2009-06-08 19:10:23 +02:00
|
|
|
|
2009-08-26 18:51:04 +02:00
|
|
|
process.addListener("exit", function () {
|
2009-11-28 18:26:59 +01:00
|
|
|
assert.equal(N+1, disconnect_count);
|
|
|
|
assert.equal(N+1, client_recv_count);
|
2009-08-26 18:51:04 +02:00
|
|
|
});
|