dns-packet/example_tcp.js
Tom Pusateri 7904e095e9 Add encoder for stream transports (TCP/TLS). (#23)
* Add encoder for stream transports (TCP/TLS).
Fixes #16.

* Add README text and return null on short buffer.
2018-02-04 19:58:34 +00:00

31 lines
606 B
JavaScript

'use strict'
const packet = require('./')
const net = require('net')
const buf = packet.streamEncode({
type: 'query',
id: 0xdead,
flags: packet.RECURSION_DESIRED,
questions: [{
type: 'A',
name: 'google.com'
}]
})
const client = new net.Socket()
client.connect(53, '8.8.8.8', function () {
console.log('Connected')
client.write(buf)
})
client.on('data', function (data) {
console.log('Received response')
console.log(packet.streamDecode(data))
client.destroy() // kill client after server's response
})
client.on('close', function () {
console.log('Connection closed')
})