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.
50 lines
1.1 KiB
50 lines
1.1 KiB
include("mjsunit");
|
|
function onLoad() {
|
|
server = new Server(1024);
|
|
var count = 0;
|
|
server.listenTCP(12123, function (connection) {
|
|
puts("got connection.");
|
|
connection.onRead = function (data) {
|
|
assertTrue(count <= 10);
|
|
if (data === null) {
|
|
server.close();
|
|
connection.close();
|
|
return;
|
|
}
|
|
stdout.write ("-");
|
|
if (/QUIT/.exec(data)) {
|
|
server.close();
|
|
connection.close();
|
|
} else if (/PING/.exec(data)) {
|
|
connection.write("PONG");
|
|
}
|
|
}
|
|
});
|
|
|
|
socket = new Socket;
|
|
socket.onRead = function (data) {
|
|
stdout.write (".");
|
|
assertEquals("PONG", data);
|
|
setTimeout(function() {
|
|
count += 1;
|
|
if (count < 10) {
|
|
socket.write("PING");
|
|
} else {
|
|
stdout.write ("\n");
|
|
socket.write("QUIT\n");
|
|
socket.close();
|
|
}
|
|
}, 100);
|
|
};
|
|
socket.onClose = function () {
|
|
puts("socket close.");
|
|
assertEquals(10, count);
|
|
};
|
|
|
|
socket.connectTCP(12123, "localhost", function (status) {
|
|
if(status != 0)
|
|
process.exit(1);
|
|
|
|
socket.write("PING");
|
|
});
|
|
}
|
|
|