multiple udp clients

This commit is contained in:
reality 2016-05-07 16:04:10 +00:00
parent 2b043d018b
commit aeea5a7e18
2 changed files with 9 additions and 4 deletions

View File

@ -1,6 +1,8 @@
{ {
"services": [{
"port":14628, "port":14628,
"address": "127.0.0.1", "address": "127.0.0.1",
"server": "freenode", "server": "freenode",
"channel": "#oaosidl" "channel": "#oaosidl"
}]
} }

View File

@ -6,17 +6,20 @@
var dgram = require('dgram'); var dgram = require('dgram');
var udp = function(dbot) { var udp = function(dbot) {
_.each(dbot.config.modules.udp.servers, function(data) {
var server = dgram.createSocket("udp4"); var server = dgram.createSocket("udp4");
server.on("message", function(msg, msginfo) { server.on("message", function(msg, msginfo) {
var message = msg.toString(); var message = msg.toString();
console.log(message); if (msginfo.address == data.address) {
if (msginfo.address == this.config.address) { dbot.say(data.server, data.channel, message);
dbot.say(this.config.server, this.config.channel, message);
} }
}.bind(this)); }.bind(this));
this.onLoad = function() { this.onLoad = function() {
server.bind(this.config.port); _.each(dbot.config.modules.udp.servers, function(data) {
server.bind(data.port);
});
}.bind(this); }.bind(this);
}.bind(this));
}; };
exports.fetch = function(dbot) { exports.fetch = function(dbot) {