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); })
const socket = net.connect({ host, port }, () => { socket.nodeID = nodeID; socket.lastUsed = Date.now();
const proxy_socket = net.connect(srvUrl.port, srvUrl.hostname, () => { socket.write('HTTP/1.1 200 Connection established\r\n\r\n');
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); })
net.connect(port, host, function () { socket.removeListener("error", onError); // remove this listener, otherwise it will also act as an inactivity timeout, not just connecting timeout. socket.removeListener("timeout", onTimeout); return next(null, new stream(transport(socket, options), options)); })
function makeTcpTransport(options, callback) { return makeStreamTransport( 'TCP', options.maxBytesHeaders, options.maxContentLength, function (port, host, callback) { return net.connect(port, host, callback); }, function (callback) { var server = net.createServer(callback); server.listen(options.port || 5060, options.address); return server; }, callback); }
it('should close socket for long time idle', async function() { const address = urlparse('bolt://127.0.0.1:' + port + '?serialization=hessian2', true); net.connect(address.port, address.hostname); const socket = await awaitEvent(server, 'connection'); connection = new RpcConnection({ logger, socket, classMap, maxIdleTime: 2000 }); await connection.ready(); mm(connection.logger, 'warn', msg => { assert(msg === '[RpcConnection] socket: %s is idle for %s(ms)'); }); await connection.await('close'); });
net.connect(3000, () => { const child = child_process.fork(process.argv[2], process.argv.slice[3], { silent: true }); multiplexChannels([child.stdout, child.stderr], socket); })
net.connect({ host: host, port: port}, () => { log('connected to', host, 'on port', port); process.stdin.on('data', (data) => { var line = data.toString('utf8'); line = line.slice(0, line.length-1) + '\r\n'; socket.write(line); }); socket.pipe(process.stdout); })
net.connect(options, function () { var header = 'GET /ISAPI/Event/notification/alertStream HTTP/1.1\r\n' + 'Host: ' + options.host + ':' + options.port + '\r\n' + authHeader + '\r\n' + 'Accept: multipart/x-mixed-replace\r\n\r\n'; client.write(header) client.setKeepAlive(true,1000) NetKeepAlive.setKeepAliveInterval(client,5000) // sets TCP_KEEPINTVL to 5s NetKeepAlive.setKeepAliveProbes(client, 12) // 60s and kill the connection. handleConnection(self, options); })
net.connect({ host: config.ip, port: 9993 }, function() { logger.info('Socket connected.'); socketConnected = true; // wait for the hyperdeck to confirm it's ready and connected. handleConnectionResponse(); })
net.connect(config.SOCKET_PATH, function() { log(`connected to ${config.SOCKET_PATH}`) client.write(`GET /containers/json ${HTTP_HEADERS}`) })
net.connect(options, function(socket) { // host is online cb && cb( null, { isAlive: true } ) client.end() })
net.connect({port: 17001, host: "10.112.125.76"}, function() { //'connect' listener console.log('connected to server!'); client.write('SignOn\tS002\tS002\r\n'); })
it('should handle socket error', async function() { const address = urlparse('bolt://127.0.0.1:' + port + '?serialization=hessian2', true); const clientSocket = net.connect(address.port, address.hostname); const socket = await awaitEvent(server, 'connection'); connection = new RpcConnection({ logger, socket, classMap }); await connection.ready(); mm(connection.logger, 'warn', msg => { assert(msg === '[RpcConnection] error occured on socket: %s, errName: %s, errMsg: %s'); }); clientSocket.write(Buffer.from('hello world++++++++++++++++++++++++++++++++')); await connection.await('close'); });