From 7b6c618b716c92da9c792fa7df84d0b0f672f217 Mon Sep 17 00:00:00 2001 From: Adam Nielsen Date: Thu, 31 Jan 2019 14:38:43 +1000 Subject: [PATCH] fix(transport): Correctly handle messages from non-standard BACnet port numbers --- lib/transport.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/transport.js b/lib/transport.js index 721574d9..b676aecc 100644 --- a/lib/transport.js +++ b/lib/transport.js @@ -3,12 +3,14 @@ const createSocket = require('dgram').createSocket; const EventEmitter = require('events').EventEmitter; +const DefaultBACnetPort = 47808; + class Transport extends EventEmitter { constructor(settings) { super(); this._settings = settings; this._server = createSocket({type: 'udp4', reuseAddr: true}); - this._server.on('message', (msg, rinfo) => this.emit('message', msg, rinfo.address)); + this._server.on('message', (msg, rinfo) => this.emit('message', msg, rinfo.address + (rinfo.port === DefaultBACnetPort ? '' : ':' + rinfo.port))); this._server.on('error', (err) => this.emit('message', err)); } @@ -21,7 +23,8 @@ class Transport extends EventEmitter { } send(buffer, offset, receiver) { - this._server.send(buffer, 0, offset, this._settings.port, receiver); + const [address, port] = receiver.split(':'); + this._server.send(buffer, 0, offset, port || DefaultBACnetPort, address); } open() {