move examples to examples directory, update readme and changelog
This commit is contained in:
@@ -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')
|
||||
})
|
||||
@@ -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')
|
||||
Reference in New Issue
Block a user