diff --git a/lib/units/device/plugins/forward.js b/lib/units/device/plugins/forward.js index 31840995..698470a4 100644 --- a/lib/units/device/plugins/forward.js +++ b/lib/units/device/plugins/forward.js @@ -71,17 +71,19 @@ module.exports = syrup.serial() .on('packet', function(fd, packet) { var proxy = proxies[fd] - if (!proxy) { - // New connection - proxy = proxies[fd] = new Proxy(fd) - } + if (packet) { + if (!proxy) { + // New connection + proxy = proxies[fd] = new Proxy(fd) + } - proxy.dest.write(packet) - }) - .on('fin', function(fd) { - // The connection ended - if (proxies[fd]) { - proxies[fd].stop() + proxy.dest.write(packet) + } + else { + // The connection ended + if (proxy) { + proxy.stop() + } } }) diff --git a/lib/util/forwardutil.js b/lib/util/forwardutil.js index 7314cf07..b6f7711a 100644 --- a/lib/util/forwardutil.js +++ b/lib/util/forwardutil.js @@ -48,7 +48,7 @@ ForwardParser.prototype._transform = function(chunk, encoding, done) { if (this._needLength === 0) { // This is a fin packet - this.emit('fin', this._target) + this.emit('packet', this._target, null) this._needLength = -HEADER_SIZE } }