@coxy/tcp-router
v2.0.0
Published
TCP router (net module) with aes & diffie-hellman
Downloads
4
Readme
Client
async function run () {
const client = new TcpClient({
port: 1337,
secret: 'supersecretstring'
})
client.on('close', () => {
console.log('close')
})
client.on('connect', () => {
console.log('connect')
})
client.on('error', () => {
console.log('error')
})
await client.connect()
const response = await client.send('/app/test', { test: 123 })
console.log(response)
}
run()
Server
import { TcpRouter } from '../tcp-router'
const router = new TcpRouter({
port: 1337,
host: '127.0.0.1',
secret: 'supersecretstring',
whitelist: ['127.0.0.1'],
maxConnections: 1
})
router.on('connect', (socket) => {
console.log('connect', socket.address())
})
router.on('close', (socket) => {
console.log('close', socket.address())
})
router.on('error:whitelist', (socket) => {
console.log(socket.address())
})
router.on('error:maxConnections', (socket) => {
console.log(socket.address())
})
router.use('/app/test', async function (ctx, next) {
ctx.body = 'test'
next()
})
void router.listen()