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.
53 lines
1.1 KiB
53 lines
1.1 KiB
16 years ago
|
include("mjsunit.js");
|
||
16 years ago
|
var N = 50;
|
||
16 years ago
|
var port = 8921;
|
||
|
|
||
16 years ago
|
var disconnect_count = 0;
|
||
|
var client_recv_count = 0;
|
||
|
|
||
16 years ago
|
function onLoad () {
|
||
|
|
||
16 years ago
|
var server = node.tcp.createServer(function (socket) {
|
||
16 years ago
|
socket.addListener("connect", function () {
|
||
16 years ago
|
socket.send("hello\r\n");
|
||
16 years ago
|
});
|
||
16 years ago
|
|
||
16 years ago
|
socket.addListener("eof", function () {
|
||
16 years ago
|
socket.close();
|
||
16 years ago
|
});
|
||
16 years ago
|
|
||
16 years ago
|
socket.addListener("disconnect", function (had_error) {
|
||
16 years ago
|
//puts("server had_error: " + JSON.stringify(had_error));
|
||
|
assertFalse(had_error);
|
||
16 years ago
|
});
|
||
16 years ago
|
});
|
||
|
server.listen(port);
|
||
16 years ago
|
|
||
|
var client = node.tcp.createConnection(port);
|
||
16 years ago
|
|
||
16 years ago
|
client.setEncoding("UTF8");
|
||
16 years ago
|
|
||
16 years ago
|
client.addListener("connect", function () {
|
||
16 years ago
|
puts("client connected.");
|
||
16 years ago
|
});
|
||
16 years ago
|
|
||
16 years ago
|
client.addListener("receive", function (chunk) {
|
||
16 years ago
|
client_recv_count += 1;
|
||
16 years ago
|
assertEquals("hello\r\n", chunk);
|
||
|
client.fullClose();
|
||
16 years ago
|
});
|
||
16 years ago
|
|
||
16 years ago
|
client.addListener("disconnect", function (had_error) {
|
||
16 years ago
|
assertFalse(had_error);
|
||
16 years ago
|
if (disconnect_count++ < N)
|
||
16 years ago
|
client.connect(port); // reconnect
|
||
|
else
|
||
|
server.close();
|
||
16 years ago
|
});
|
||
16 years ago
|
}
|
||
16 years ago
|
|
||
|
function onExit () {
|
||
|
assertEquals(N+1, disconnect_count);
|
||
|
assertEquals(N+1, client_recv_count);
|
||
|
}
|