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.
52 lines
1.0 KiB
52 lines
1.0 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 = new node.tcp.Server(function (socket) {
|
||
16 years ago
|
socket.onConnect = function () {
|
||
|
socket.send("hello\r\n");
|
||
|
};
|
||
|
|
||
|
socket.onEOF = function () {
|
||
|
socket.close();
|
||
|
};
|
||
|
|
||
16 years ago
|
socket.onDisconnect = function (had_error) {
|
||
|
//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 = new node.tcp.Connection();
|
||
|
|
||
16 years ago
|
client.setEncoding("UTF8");
|
||
16 years ago
|
client.onConnect = function () {
|
||
|
};
|
||
|
|
||
|
client.onReceive = function (chunk) {
|
||
16 years ago
|
client_recv_count += 1;
|
||
16 years ago
|
assertEquals("hello\r\n", chunk);
|
||
|
client.fullClose();
|
||
|
};
|
||
|
|
||
16 years ago
|
client.onDisconnect = function (had_error) {
|
||
|
assertFalse(had_error);
|
||
16 years ago
|
if (disconnect_count++ < N)
|
||
16 years ago
|
client.connect(port); // reconnect
|
||
|
else
|
||
|
server.close();
|
||
16 years ago
|
};
|
||
|
|
||
|
client.connect(port);
|
||
|
}
|
||
16 years ago
|
|
||
|
function onExit () {
|
||
|
assertEquals(N+1, disconnect_count);
|
||
|
assertEquals(N+1, client_recv_count);
|
||
|
}
|