diff --git a/lib/STP.js b/lib/STP.js index c27dd96..08630cc 100644 --- a/lib/STP.js +++ b/lib/STP.js @@ -63,6 +63,8 @@ class STPSocket extends EventEmitter { else this.tcpSocket.on('connect', this.handshake.bind(this)); this.tcpSocket.on('data', this.data.bind(this)); + this.tcpSocket.on('error', (...args) => this.emit('error', ...args)); + this.tcpSocket.on('close', (...args) => this.emit('close', ...args)); } data(evt) { diff --git a/relay/index.js b/relay/index.js index 92f1018..3ff22bf 100644 --- a/relay/index.js +++ b/relay/index.js @@ -22,6 +22,11 @@ let client = null; client = null; setTimeout(tryConnect, 1000); }); + client.on('close', () => { + log.error(`connection closed on ${config.addresses.relay}`) + client = null; + setTimeout(tryConnect, 1000); + }); client.on('data', (data) => { log.debug(data.toString()); }) @@ -55,10 +60,12 @@ app.get('/', (req, res) => {
${client.remoteAddress}
${client.remoteIdentity}
- `)} + `).join('')} `); -}) +}); + +// app.post app.listen(9999);