2009-10-29 23:34:10 +01:00
|
|
|
process.mixin(require("common.js"));
|
2009-09-28 16:08:09 +02:00
|
|
|
tcp = require("/tcp.js");
|
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-06-04 12:31:45 +02:00
|
|
|
assertFalse(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);
|
|
|
|
assertEquals("hello\r\n", chunk);
|
|
|
|
client.close();
|
|
|
|
});
|
|
|
|
|
|
|
|
client.addListener("close", function (had_error) {
|
|
|
|
puts("disconnect");
|
|
|
|
assertFalse(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-06-08 19:10:23 +02:00
|
|
|
assertEquals(N+1, disconnect_count);
|
|
|
|
assertEquals(N+1, client_recv_count);
|
2009-08-26 18:51:04 +02:00
|
|
|
});
|