commit
This commit is contained in:
25
node/index.js
Normal file
25
node/index.js
Normal 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
13
node/package.json
Normal 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"
|
||||
}
|
||||
Reference in New Issue
Block a user