Initial commit
This commit is contained in:
commit
3090e740f6
8
.idea/.gitignore
vendored
Normal file
8
.idea/.gitignore
vendored
Normal 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
|
||||||
6
.idea/jsLibraryMappings.xml
Normal file
6
.idea/jsLibraryMappings.xml
Normal 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
8
.idea/modules.xml
Normal 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
8
.idea/tcp_servers.iml
Normal 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
30
index.js
Normal 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
6
package.json
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"name": "tcp_servers",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"main": "index.js",
|
||||||
|
"license": "MIT"
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user