commit 3090e740f6c06b58bd99f54479aee186250d5205 Author: xl1034 Date: Sun Oct 27 23:39:16 2024 +0700 Initial commit diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/jsLibraryMappings.xml b/.idea/jsLibraryMappings.xml new file mode 100644 index 0000000..d23208f --- /dev/null +++ b/.idea/jsLibraryMappings.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..7deecb8 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/tcp_servers.iml b/.idea/tcp_servers.iml new file mode 100644 index 0000000..c956989 --- /dev/null +++ b/.idea/tcp_servers.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..48e734d --- /dev/null +++ b/index.js @@ -0,0 +1,30 @@ +const readline = require('readline'); +const net = require('net'); + +const rl = readline.createInterface({ + input: process.stdin, + output: process.stdout +}); + +rl.question('Сколько серверов создать? (По умолчанию 5): ', (answer) => { + const numberOfServers = parseInt(answer) || 5; + + for (let i = 0; i < numberOfServers; i++) { + const server = net.createServer((socket) => { + console.log(`Сервер на порту ${2000 + i} - Подключился клиент`); + socket.on('data', (data) => { + console.log(`Сервер на порту ${2000 + i} - Получены данные: ${data}`); + }); + }); + + server.on('close', () => { + console.log(`Сервер на порту ${2000 + i} - Отключен`); + }); + + server.listen(2000 + i, () => { + console.log(`Сервер на порту ${2000 + i} - Ожидание подключений`); + }); + } + + rl.close(); +}); diff --git a/package.json b/package.json new file mode 100644 index 0000000..7ea9ec4 --- /dev/null +++ b/package.json @@ -0,0 +1,6 @@ +{ + "name": "tcp_servers", + "version": "1.0.0", + "main": "index.js", + "license": "MIT" +}