我想测量通过 tcp 连接发送 x 数量的 pkts 和 n 字节所需的时间。唯一的问题是我的数据包正在合并。我知道 TCP 默认情况下会这样做,但我如何让它立即发送它们,甚至合并数据包。
客户:
var net = require('net');
var HOST = '127.0.0.1';
var PORT = 6969;
var number_packets = 2500;
var packet_size = 200;
var client = new net.Socket();
client.connect(PORT, HOST, function() {
client.setNoDelay(true);
for (var i = 0; i <= 100; i++) {
var message = new Buffer(packet_size);
console.log('Sending message #: '+i);
client.write(message);
}
});
client.on('data', function(data) {
console.log('DATA: ' + data);
// Close the client socket completely
client.destroy();
});
client.on('close', function() {
console.log('Connection closed');
});
服务器:
var net = require('net');
var HOST = '127.0.0.1';
var PORT = 6969;
var count = 1;
net.createServer(function(sock) {
sock.on('data', function(data) {
var size = data.length;
console.log('pkt: '+count+' size: '+size);
//sock.write(data+'-');
count++;
});
sock.on('close', function(data) {
console.log('CLOSED: ' + sock.remoteAddress +' '+ sock.remotePort);
});
}).listen(PORT, HOST);
//console.log('Server listening on ' + HOST +':'+ PORT);