node.js - Node.js 中的并发请求
问题描述
我想提交并发客户端请求以检查我的服务器功能。
如何在单线程的节点环境中实现它?我想在线程中同时运行以下代码。
以下是我的代码: -
var net = require('net');
var sleep = require('system-sleep');
var express= require('express');
module.exports = {
Activation:function() {
var client = new net.Socket();
client.setTimeout(60000);
var strSendData="6534265365342135425366532121323767";
var sendData = Buffer.from(strSendData, 'hex');
console.log('Connecting...');
client.connect(8094, '192.168.126.129', function(data,err) {
if (err) {
console.log('Not able to connect with server');
} else {
console.log('Connected');
client.write(sendData);
}
});
client.on('data', function(data) {
console.log('Received: ' + data);
client.destroy(); // kill client after server's response
});
client.on('close', function() {
console.log('Connection closed');
});
}
}
解决方案
推荐阅读
- javascript - Javascript 确认,即使取消也会运行表单
- nginx - 配置 NextCloud 和 Nginx 反向端口转发 - 登录验证错误
- javascript - 如何访问 Vuex 模块中的 Vue 对象?
- google-drive-api - 是否可以将 Google Drive UI 或框架添加到现有网站中?
- python - 从 JSON 请求创建 pandas 数据框
- shiny - 异步:点击 actionButton 时显示进度并禁用同一用户的其他操作但允许并发用户
- python - 替换文件中的行的代码是重复行
- powershell - 在 Kotlin 中运行 powershell 脚本而不创建文件
- r - 蒙特卡罗模拟错误,不会更新计数
- identityserver3 - 提供的证书对加密/解密无效