move examples to examples directory, update readme and changelog

This commit is contained in:
silverwind
2018-02-04 21:06:09 +01:00
parent 7904e095e9
commit 868e488530
4 changed files with 15 additions and 2 deletions
+30
View File
@@ -0,0 +1,30 @@
'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')
})
+23
View File
@@ -0,0 +1,23 @@
'use strict'
const packet = require('./')
const dgram = require('dgram')
const socket = dgram.createSocket('udp4')
const buf = packet.encode({
type: 'query',
id: 1,
flags: packet.RECURSION_DESIRED,
questions: [{
type: 'A',
name: 'google.com'
}]
})
socket.on('message', function (message, rinfo) {
console.log(rinfo)
console.log(packet.decode(message)) // prints out a response from google dns
})
socket.send(buf, 0, buf.length, 53, '8.8.8.8')