constructor(frontend) { process.title = 'ndb/ndd_service'; this._disconnectPromise = new Promise(resolve => process.once('disconnect', () => resolve(DebugState.PROCESS_DISCONNECT))); this._connected = new Set(); this._frontend = frontend; const pipePrefix = process.platform === 'win32' ? '\\\\.\\pipe\\' : os.tmpdir(); const pipeName = `node-ndb.${process.pid}.sock`; this._pipe = path.join(pipePrefix, pipeName); const server = net.createServer(socket => { socket.on('data', async d => { const runSession = await this._startSession(JSON.parse(d), frontend); socket.write('run'); runSession(); }); socket.on('error', e => caughtErrorDebug(e)); }).listen(this._pipe); server.unref(); }
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); })
socket.write(process.env.NDD_PUBLISH_DATA); const timeoutId = setTimeout(() => socket.destroy(), TIMEOUT); socket.on('data', () => { clearTimeout(timeoutId); socket.destroy(); }); }); socket.on('error', err => { process.stderr.write('\u001b[31mndb is not found:\u001b[0m\n'); process.stderr.write('please restart it and update env variables or unset NDD_IPC and NODE_OPTIONS.\n');
async function openClientConnection(channelName, readerUuid) { const pathToSocket = socketPath(channelName, readerUuid); const client = new net.Socket(); return new Promise((res, rej) => { client.connect( pathToSocket, () => res(client) ); client.on('error', err => rej(err)); }); }
self._server.on('connect', connectFn); }); socket.on('error', (err) => { winston.error('[LocalProxy/%s] connect (error client) %s => %s', self._name, req.url, err.toString()); }); proxy_socket.on('error', (err) => { winston.error('[LocalProxy/%s] connect (error proxy) %s => %s', self._name, req.url, err.toString());
logger.info('[MQTTConnector] listen on %d', this.port); this.server.on('error', function (err) { this.server.on('connection', (stream) => { let client = mqtt_connection(stream); client.on('error', function (err: Error) { client.destroy(); }); client.on('close', function () { client.destroy(); }); client.on('disconnect', function (packet: any) { client.destroy(); }); stream.on('timeout', function () { client.destroy(); }); client.on('publish', function (packet: any) { client.on('pingreq', function () { client.on('connect', function (packet: any) { client.connack({ returnCode: 0 }); let mqttsocket = new MQTTSocket(curId++, client, self.adaptor);
req.on('error', (err) => { winston.error('[Master] Error: request error from client (%s %s on instance %s):', req.method, req.url, instance.toString(), err); socket.on('error', (err) => { winston.error('[Master] Error: socket error from client (%s %s on instance %s):', req.method, req.url, instance.toString(), err); proxy_req.on('error', (err) => { winston.error('[Master] Error: request error from client (%s %s on instance %s):', req.method, req.url, instance.toString(), err); proxy_req.on('connect', (instance_req, proxy_socket) => { proxy_socket.on('error', (err) => { winston.error('[Master] Error: response error from target (%s %s on instance %s):', req.method, req.url, instance.toString(), err); }); proxy_socket.on('end', () => {
this.client.on('data', data => { debug(`Received data: ${data.toString('hex')}`); this.client.on('error', err => { debug('Error event from socket.', this.device.ip, err); this.client.on('close', () => { debug(`Socket closed: ${this.device.ip}`); this.client.on('connect', async () => { debug('Socket connected.');
net.createServer(function(connection) { console.log('client connected'); connection.on('end', function() { console.log('客户端关闭连接'); }); connection.write('Hello World!\r\n'); connection.pipe(connection); })
net.connect(port, hostname, function () { socket.write('HTTP/1.1 200 Connection Established\r\n\r\n'); proxySocket.write(head); proxySocket.pipe(socket); }).on('error', function (e) { log.error('proxy error', e.message); log.detail('proxy error', e.stack); socket.end(); }).on('data', function (data) { // console.log('proxy socker data:', hostname, port, data.toString()); // socket.write(data); })