diff --git a/lib/transport.socket.js b/lib/transport.socket.js index 2c0b901a..5a49b09f 100644 --- a/lib/transport.socket.js +++ b/lib/transport.socket.js @@ -208,8 +208,6 @@ SocketTransport.prototype.end = function(data) { } else { this.socket.end(); } - - this.socket.destroy(); }; // Socket data handler @@ -222,7 +220,7 @@ SocketTransport.prototype._onSocketData = function(chunk) { try { this._buffer = jsrs.parseNetworkPackets(this._buffer, packets); } catch (error) { - this.emit('error', error); + this.socket.destroy(error); return; } diff --git a/lib/transport.ws.js b/lib/transport.ws.js index 363f4b28..f602cd03 100644 --- a/lib/transport.ws.js +++ b/lib/transport.ws.js @@ -101,8 +101,7 @@ function JstpWebSocketServer(httpServer, config, 'listening', 'close' ]); - - this.httpServer.on('clientError', this._onSocketError.bind(this)); + common.forwardEvent(httpServer, this, 'clientError', 'error'); this.wsServer = new WebSocketServer(this.config); this.wsServer.on('request', this._onRequest.bind(this)); @@ -147,13 +146,6 @@ JstpWebSocketServer.prototype._onRequest = function(request) { this.emit('connection', connection); }; -// Socket error handler -// -JstpWebSocketServer.prototype._onSocketError = function(error, socket) { - socket.destroy(); - this.emit('error', error); -}; - // Default originCheckStrategy value for ws.createClient and // JstpWebSocketServer constructor //