Skip to content
This repository has been archived by the owner on Dec 2, 2020. It is now read-only.

Allow one to specify a bind address for http, udp, fixes problem when udp disabled. #138

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions lib/cube/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,19 @@ module.exports = function(options) {
if (error) throw error;
server.register(db, endpoints);
meta = require("./event").putter(db);
util.log("starting http server on port " + options["http-port"]);
primary.listen(options["http-port"]);
if (endpoints.udp) {
util.log("starting udp server on port " + options["udp-port"]);
var http_addr = options["http-addr"];
if (http_addr === undefined) http_addr = "0.0.0.0";
util.log("starting http server on " + http_addr + ":" + options["http-port"]);
primary.listen(options["http-port"], http_addr);
if (endpoints.udp && options["udp-port"] !== undefined) {
var udp_addr = options["udp-addr"];
if (udp_addr === undefined) udp_addr = "0.0.0.0";
util.log("starting udp server on " + udp_addr + ":" + options["udp-port"]);
var udp = dgram.createSocket("udp4");
udp.on("message", function(message) {
endpoints.udp(JSON.parse(message.toString("utf8")), ignore);
});
udp.bind(options["udp-port"]);
udp.bind(options["udp-port"], udp_addr);
}
});
};
Expand Down