Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

make server example listen on both tcp and udp

  • Loading branch information...
commit 98b54e6d22aaffb5112c54895633a24c7fd0b4e2 1 parent b9ddbd3
@tjfontaine authored
Showing with 37 additions and 11 deletions.
  1. +37 −11 examples/server.js
View
48 examples/server.js
@@ -1,9 +1,11 @@
"use strict";
var dns = require('../dns'),
+ tcpserver = dns.createTCPServer(),
server = dns.createServer();
-server.on('request', function (request, response) {
+var onMessage = function (request, response) {
+ var i;
//console.log(request)
response.answer.push(dns.A({
name: request.question[0].name,
@@ -20,24 +22,48 @@ server.on('request', function (request, response) {
address: '127.0.0.3',
ttl: 600,
}));
+
+ //To force truncation and tcp tests
+ //for (i = 1; i < 254; i++) {
+ // response.additional.push(dns.A({
+ // name: 'host'+i+'.example.org',
+ // address: '127.0.0.' + 1,
+ // ttl: 600,
+ // }));
+ //}
+
response.send();
-});
+};
-server.on('error', function (err, buff, req, res) {
+var onError = function (err, buff, req, res) {
console.log(err.stack);
-});
+};
-server.on('listening', function () {
+var onListening = function () {
console.log('server listening on', this.address());
//this.close();
-});
+};
-server.on('socketError', function (err, socket) {
+var onSocketError = function (err, socket) {
console.log(err);
-});
+};
+
+var onClose = function () {
+ console.log('server closed', this.address());
+};
-server.on('close', function () {
- console.log('server closed');
-});
+server.on('request', onMessage);
+server.on('error', onError);
+server.on('listening', onListening);
+server.on('socketError', onSocketError);
+server.on('close', onClose);
server.serve(15353, '127.0.0.1');
+
+tcpserver.on('request', onMessage);
+tcpserver.on('error', onError);
+tcpserver.on('listening', onListening);
+tcpserver.on('socketError', onSocketError);
+tcpserver.on('close', onClose);
+
+tcpserver.serve(15353, '127.0.0.1');
Please sign in to comment.
Something went wrong with that request. Please try again.