const methodCall = (connectionMethod, methodName, parameters) => new Promise((resolve, reject) => { const networkConfiguration = connectionMethod.socketPath != null ? {path: connectionMethod.socketPath} : {port: connectionMethod.port, host: connectionMethod.host}; const stream = net.connect(networkConfiguration); const xml = Serializer.serializeMethodCall(methodName, parameters); const xmlLength = Buffer.byteLength(xml, 'utf8'); stream.on('error', reject); stream.setEncoding('UTF8'); const headerItems = [`CONTENT_LENGTH${NULL_CHAR}${xmlLength}${NULL_CHAR}`, `SCGI${NULL_CHAR}1${NULL_CHAR}`]; const headerLength = headerItems.reduce((accumulator, headerItem) => accumulator + headerItem.length, 0); stream.end(`${headerLength}:${headerItems.join('')},${xml}`); bufferStream(stream) .then(data => { rTorrentDeserializer.deserialize(data, resolve, reject); }) .catch(reject); })
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); } } }
remote.on('error', function(err) { // emit connection refused errors immediately, because they // indicate that the tunnel can't be established. if (err.code === 'ECONNREFUSED') { self.emit('error', new Error('connection refused: ' + remote_host + ':' + remote_port + ' (check your firewall settings)')); } remote.end(); });
const tryConnection = () => client.connect({ port }, () => { client.end() if (!startedElectron) { console.log('starting electron') startedElectron = true const exec = require('child_process').exec exec('yarn electron') } })
net.createServer(function(socket) { var date = new Date(); var month = date.getMonth() + 1; if (month < 9) { month = '0' + month; } socket.write(date.getFullYear() + '-' + month + '-' + date.getDate() + ' ' + date.getHours() + ':' + date.getMinutes()); socket.end(); // socket.end('hello'); })
async function checkPortListening(port) { const listening = new Promise(resolve => { const client = Net.createConnection({ port }); client.setTimeout(100); client.on("error", () => resolve(false)); client.on("connect", () => { client.end(); resolve(true); }); }); return listening; }
socket.once('data', chunk => { console.log('SSH server version: %j', chunk.trim()); socket.pipe(socket) socket.end() })
async checkRemotePort(server, port) { logger.debug(`Check remote port is accessible for: ${server}:${port}`); return new Promise(async (resolve, reject) => { let client = net.createConnection({host: server, port: port, timeout: 1000}, ()=>{ logger.debug(`Remote port is accessible: ${server}:${port}`); client.end(); resolve(); }); client.on("error", e => { reject(`Endpoint is unreachable: ${server}:${port}. ${e && e.message}`) }); }); }
this.socket.on('close', function (err) { self.connected = false; self.emit('close', err); self.socket.end(); console.log('[Node Debugger] Disconnected'); });
net.connect(options, function(socket) { // host is online cb && cb( null, { isAlive: true } ) client.end() })
client.on('data', (data) => { console.log(data.toString()); client.end(); });
client.on('close', function(code, reason) { log('WebSocket client disconnected: ' + code + ' [' + reason + ']'); target.end(); });
remote.on('error', function(err) { // emit connection refused errors immediately, because they // indicate that the tunnel can't be established. if (err.code === 'ECONNREFUSED') { self.emit('error', new Error('connection refused: ' + remote_host + ':' + remote_port + ' (check your firewall settings)')); } remote.end(); });
client.on('data', function(data) { console.log(data.toString()); client.end(); });
logs.on('exit', function(code) { console.log('child process exited with code ' + code); client.end(); });