Files
DefinitelyTyped/types/net-keepalive/net-keepalive-tests.ts
Giorgi Kotchlamazashvili f2094c7891 Added type definitions for net-keepalive (#20403)
* Added type definitions for net-keepalive

* fixes linting issues

* Enables no-unnecessary-generics rule while linting
2017-10-09 15:31:41 -07:00

21 lines
681 B
TypeScript

import NetKeepAlive = require('net-keepalive')
import * as Net from 'net'
const server = Net.createServer((socket) => {
socket.setKeepAlive(true, 1000)
NetKeepAlive.setKeepAliveInterval(socket, 1000)
NetKeepAlive.setKeepAliveProbes(socket, 1)
socket.on('end', () => server.close())
})
server.listen(1337, '127.0.0.1', () => {
const {port, address} = server.address()
const clientSocket = Net.createConnection({
port, host: address
}, () => {
clientSocket.setKeepAlive(true, 1000)
NetKeepAlive.setKeepAliveInterval(clientSocket, 1000)
NetKeepAlive.setKeepAliveProbes(clientSocket, 1)
clientSocket.end()
})
})