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')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user