function connect(port) { return new Promise(resolve => { const socket = net.createConnection(port, '127.0.0.1', () => { socket.write('GET http://127.0.0.1:8080/ HTTP', () => { socket.destroy(); resolve(); }); }); }); }
disconnect() { if (this.state === ST_CLOSED) { return; } this.state = ST_CLOSED; this.socket.stream.destroy(); }
close() { if (!!this.closeMethod && this.closeMethod === 'end') { this._socket.end(); } else { try { this._socket.destroy(); } catch (e) { logger.error('socket close with destroy error: %j', e.stack); } } }
/** * Disconnects from the device, use to * close the socket and exit gracefully. */ disconnect() { debug('Disconnect'); this._connected = false; // Clear timeouts clearTimeout(this._sendTimeout); clearTimeout(this._connectTimeout); clearTimeout(this._responseTimeout); clearTimeout(this.pingpongTimeout); if (!this.client) { return; } this.client.destroy(); }
assert.equal(emitted[0], 'foobar'); client.destroy(); socket.server.close(); });
async close() { await this.client.destroy() this.client.unref() this.closed = true }
serviceClient.on('close', hadError => { if (!connectionToServerLost) { connectionToServerLost = true log.info('Connection to server lost') } if (pinger) clearInterval(pinger) if (!serviceClient.destroyed) serviceClient.destroy() isDataClient = false connectWithDelay(5000) })
close() { return new Promise(resolve => { if (!this.connected) return resolve(); this._socket.once('close', () => resolve()); this._socket.destroy(); }); }
/** * 强制关闭连接,不等正在进行中的请求 * * @param {Error} [err] - 关闭的异常 */ async forceClose(err) { if (this._closed) { return; } this._lastError = err; this._socket.destroy(); await this.await('close'); }
const socketClose = () => { clientSocket.destroy() removeListeners() }
var exit = function() { console.log("\nBye."); client.destroy(); process.stdin.pause(); }
serviceAgent.on('close', hadError => { if (!connectionToServerLost) { connectionToServerLost = true log.info('Connection to server lost') } if (pinger) clearInterval(pinger) dataPort = undefined serviceAgent.destroy() if (!fatalError) { connectWithDelay(50000) } })