Initial commit

This commit is contained in:
xl1034 2024-10-27 23:39:16 +07:00
commit 3090e740f6
6 changed files with 66 additions and 0 deletions

8
.idea/.gitignore vendored Normal file
View File

@ -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

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptLibraryMappings">
<includedPredefinedLibrary name="Node.js Core" />
</component>
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/tcp_servers.iml" filepath="$PROJECT_DIR$/.idea/tcp_servers.iml" />
</modules>
</component>
</project>

8
.idea/tcp_servers.iml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

30
index.js Normal file
View File

@ -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();
});

6
package.json Normal file
View File

@ -0,0 +1,6 @@
{
"name": "tcp_servers",
"version": "1.0.0",
"main": "index.js",
"license": "MIT"
}