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.
54 lines
1.2 KiB
54 lines
1.2 KiB
15 years ago
|
process.mixin(require("../common"));
|
||
15 years ago
|
tcp = require("tcp");
|
||
16 years ago
|
var N = 50;
|
||
16 years ago
|
var port = 8921;
|
||
|
|
||
16 years ago
|
var c = 0;
|
||
16 years ago
|
var client_recv_count = 0;
|
||
16 years ago
|
var disconnect_count = 0;
|
||
16 years ago
|
|
||
15 years ago
|
var server = tcp.createServer(function (socket) {
|
||
16 years ago
|
socket.addListener("connect", function () {
|
||
15 years ago
|
socket.write("hello\r\n");
|
||
16 years ago
|
});
|
||
16 years ago
|
|
||
15 years ago
|
socket.addListener("end", function () {
|
||
16 years ago
|
socket.close();
|
||
16 years ago
|
});
|
||
16 years ago
|
|
||
16 years ago
|
socket.addListener("close", function (had_error) {
|
||
|
//puts("server had_error: " + JSON.stringify(had_error));
|
||
15 years ago
|
assert.equal(false, had_error);
|
||
16 years ago
|
});
|
||
16 years ago
|
});
|
||
|
server.listen(port);
|
||
|
|
||
15 years ago
|
var client = tcp.createConnection(port);
|
||
16 years ago
|
|
||
|
client.setEncoding("UTF8");
|
||
|
|
||
|
client.addListener("connect", function () {
|
||
|
puts("client connected.");
|
||
|
});
|
||
|
|
||
15 years ago
|
client.addListener("data", function (chunk) {
|
||
16 years ago
|
client_recv_count += 1;
|
||
|
puts("client_recv_count " + client_recv_count);
|
||
15 years ago
|
assert.equal("hello\r\n", chunk);
|
||
16 years ago
|
client.close();
|
||
|
});
|
||
|
|
||
|
client.addListener("close", function (had_error) {
|
||
|
puts("disconnect");
|
||
15 years ago
|
assert.equal(false, 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
|
process.addListener("exit", function () {
|
||
15 years ago
|
assert.equal(N+1, disconnect_count);
|
||
|
assert.equal(N+1, client_recv_count);
|
||
16 years ago
|
});
|