2009-06-08 15:30:10 +02:00
|
|
|
include("mjsunit.js");
|
2009-06-08 19:10:23 +02:00
|
|
|
var N = 50;
|
2009-05-19 21:53:26 +02:00
|
|
|
var port = 8921;
|
|
|
|
|
2009-06-08 19:10:23 +02:00
|
|
|
var disconnect_count = 0;
|
|
|
|
var client_recv_count = 0;
|
|
|
|
|
2009-05-19 21:53:26 +02:00
|
|
|
function onLoad () {
|
|
|
|
|
2009-06-26 12:51:27 +02:00
|
|
|
var server = node.tcp.createServer(function (socket) {
|
2009-06-27 20:40:43 +02:00
|
|
|
socket.addListener("Connect", function () {
|
2009-05-19 21:53:26 +02:00
|
|
|
socket.send("hello\r\n");
|
2009-06-27 20:40:43 +02:00
|
|
|
});
|
2009-05-19 21:53:26 +02:00
|
|
|
|
2009-06-27 20:40:43 +02:00
|
|
|
socket.addListener("EOF", function () {
|
2009-05-19 21:53:26 +02:00
|
|
|
socket.close();
|
2009-06-27 20:40:43 +02:00
|
|
|
});
|
2009-05-19 21:53:26 +02:00
|
|
|
|
2009-06-27 20:40:43 +02:00
|
|
|
socket.addListener("Disconnect", function (had_error) {
|
2009-06-04 12:31:45 +02:00
|
|
|
//puts("server had_error: " + JSON.stringify(had_error));
|
|
|
|
assertFalse(had_error);
|
2009-06-27 20:40:43 +02:00
|
|
|
});
|
2009-06-04 12:31:45 +02:00
|
|
|
});
|
|
|
|
server.listen(port);
|
2009-05-19 21:53:26 +02:00
|
|
|
var client = new node.tcp.Connection();
|
|
|
|
|
2009-05-20 10:02:02 +02:00
|
|
|
client.setEncoding("UTF8");
|
2009-06-27 20:40:43 +02:00
|
|
|
client.addListener("Connect", function () {
|
|
|
|
});
|
2009-05-19 21:53:26 +02:00
|
|
|
|
2009-06-27 20:40:43 +02:00
|
|
|
client.addListener("Receive", function (chunk) {
|
2009-06-08 19:10:23 +02:00
|
|
|
client_recv_count += 1;
|
2009-05-19 21:53:26 +02:00
|
|
|
assertEquals("hello\r\n", chunk);
|
|
|
|
client.fullClose();
|
2009-06-27 20:40:43 +02:00
|
|
|
});
|
2009-05-19 21:53:26 +02:00
|
|
|
|
2009-06-27 20:40:43 +02:00
|
|
|
client.addListener("Disconnect", function (had_error) {
|
2009-06-04 12:31:45 +02:00
|
|
|
assertFalse(had_error);
|
2009-06-08 19:10:23 +02:00
|
|
|
if (disconnect_count++ < N)
|
2009-06-04 12:31:45 +02:00
|
|
|
client.connect(port); // reconnect
|
|
|
|
else
|
|
|
|
server.close();
|
2009-06-27 20:40:43 +02:00
|
|
|
});
|
2009-05-19 21:53:26 +02:00
|
|
|
|
|
|
|
client.connect(port);
|
|
|
|
}
|
2009-06-08 19:10:23 +02:00
|
|
|
|
|
|
|
function onExit () {
|
|
|
|
assertEquals(N+1, disconnect_count);
|
|
|
|
assertEquals(N+1, client_recv_count);
|
|
|
|
}
|