1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| 'use strict'; // port参数 let port = '1580'; let net = require('net');
// 为了http请求能复用connection连接,Nodejs在http.Agent创建了一个默认大小为5的连接池 require("http").globalAgent.maxSockets = Infinity;
let server = new net.createServer({ port: port });
server.on('connection', function (soConnection) {
soConnection.on('data', async function (data) { try {
} catch (exp) { log.error('error:' + exp); } });
soConnection.on('close', async function (code, reason) {
});
soConnection.on('error', async function (err) {
});
});
server.listen( port, '127.0.0.1', function () { console.log('running on ' + port); });
|