0
This commit is contained in:
2022-09-08 01:25:43 +03:00
commit becc7d0afd
5 changed files with 255 additions and 0 deletions

25
node/index.js Normal file
View File

@@ -0,0 +1,25 @@
import net from 'net'
const host = '127.0.0.1'
const port = 8888
const backlog = 50
const server = net.createServer()
server.listen(port, host, backlog)
server.on('connection', (client) => {
console.log('[i] client connected')
client.on('data', (data) => {
console.log('INCOMMING MESSAGE: ' + data)
})
let timerId = setInterval(() => {
client.write(JSON.stringify({"ping": Date.now()}) + "\n")
}, 1000)
client.on('close', () => {
clearTimeout(timerId)
console.log('[i] client close connection')
})
})

13
node/package.json Normal file
View File

@@ -0,0 +1,13 @@
{
"name": "node",
"version": "1.0.0",
"description": "",
"type": "module",
"main": "index.js",
"scripts": {
"run": "node index.js"
},
"keywords": [],
"author": "",
"license": "ISC"
}