Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

child_process-remote

Package Overview
Dependencies
Maintainers
3
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

child_process-remote - npm Package Compare versions

Comparing version 1.4.0 to 2.0.1

examples/http.js

31

examples/index.js
"use strict";
const net = require('net');
const Server = require('../server');

@@ -7,3 +8,4 @@ const Spawn = require('../spawn');

if(process.argv[2] == "server") {
var server = new Server();
var server = net.createServer(Server);

@@ -16,4 +18,6 @@ server.listen(8080, function() {

if(process.argv[2] == "client") {
var spawn = Spawn(8080, '127.0.0.1');
var client = net.connect(8080);
var spawn = Spawn(client);
var version = '';

@@ -28,5 +32,28 @@ var child = spawn('node', ['-v']);

console.log('All done, version is %s , exit code is %d', version, exit);
var result = '';
var child2 = spawn('node', ['-p', '40+2']);
child2.stdout.on('data', function(line) {
result = line;
})
child2.on('exit', function(exit) {
console.log("Got pid", child2.pid);
console.log('All done, response is %s , exit code is %d', result, exit);
client.destroy();
});
});
}

8

package.json
{
"name": "child_process-remote",
"version": "1.4.0",
"version": "2.0.1",
"description": "child_process spawn over TCP",

@@ -16,3 +16,3 @@ "main": "spawn.js",

"type": "git",
"url": "git+ssh://git@github.com/131/remote-cp.git"
"url": "git+ssh://git@github.com/131/child_process-remote.git"
},

@@ -27,5 +27,5 @@ "keywords": [

"bugs": {
"url": "https://github.com/131/remote-cp/issues"
"url": "https://github.com/131/child_process-remote/issues"
},
"homepage": "https://github.com/131/remote-cp#readme",
"homepage": "https://github.com/131/child_process-remote#readme",
"dependencies": {

@@ -32,0 +32,0 @@ "debug": "^2.3.2",

[![Build Status](https://travis-ci.org/131/remote-cp.svg?branch=master)](https://travis-ci.org/131/remote-cp)
[![Coverage Status](https://coveralls.io/repos/github/131/remote-cp/badge.svg?branch=master)](https://coveralls.io/github/131/remote-cp?branch=master)
[![Build Status](https://travis-ci.org/131/child_process-remote.svg?branch=master)](https://travis-ci.org/131/child_process-remote)
[![Coverage Status](https://coveralls.io/repos/github/131/child_process-remote/badge.svg?branch=master)](https://coveralls.io/github/131/child_process-remote?branch=master)
[![Version](https://img.shields.io/npm/v/child_process-remote.svg)](https://www.npmjs.com/package/child_process-remote)

@@ -11,3 +11,3 @@ [![License](https://img.shields.io/badge/license-MIT-blue.svg)](http://opensource.org/licenses/MIT)

Execute a remote process throught a remote TCP endoint
Execute a process through a remote endoint

@@ -17,5 +17,17 @@

```server.js
const net = require('net');
const Server = require('child_process-remote/server');
var server = net.createServer(Server);
server.listen(8080, function() {
console.log("Server is now ready");
});
```
```client.js
//assume server is running on
var spawn = require('child_process-remote/spawn')(8080);
//assume server is running
const net = require('net');
const spawn = require('child_process-remote/spawn')(net.connect(8080));

@@ -33,9 +45,2 @@ var version = '';

```server.js
var Server = require('child_process-remote/server');
var server = new Server();
server.listen(8080, function() {
console.log("Server is now ready");
});
```

@@ -42,0 +47,0 @@

"use strict";
const net = require('net');
const spawn = require('child_process').spawn;
const multiplex = require('multiplex');
const debug = require('debug')('remote-cp:server');
class Server {
constructor() {
this.server = net.createServer(this.incoming.bind(this));
}
const Server = function(stream, readable) {
debug("new tcp client");
listen(...listener) {
this.server.listen(...listener);
}
const armor = multiplex(incoming);
(readable || stream).pipe(armor);
armor.pipe(stream);
};
destroy() {
this.server.emit('destroy');
this.server.close();
}
async incoming(client) {
this.server.on('destroy', client.destroy.bind(client));
debug("new tcp client");
const incoming = async function(client) {
const multi = multiplex();
const multi = multiplex();
client.pipe(multi); multi.pipe(client);
client.pipe(multi);
multi.pipe(client);
const control = multi.createSharedStream('control');
const remotestdout = multi.createStream('stdout');
const remotestderr = multi.createStream('stderr');
const remotestdin = multi.receiveStream('stdin');
var control = multi.createSharedStream('control');
var remotestdout = multi.createStream('stdout');
var remotestderr = multi.createStream('stderr');
var remotestdin = multi.receiveStream('stdin');
var data = await new Promise(resolve => control.once('data', resolve));
data = JSON.parse(data);
debug("Got payload", data);
var data = await new Promise(resolve => control.once('data', resolve));
var child = spawn(...data.query);
var payload = { type : 'pid', pid : child.pid };
debug("ACK pid", payload);
control.write(JSON.stringify(payload));
control.on('data', function(data) {
data = JSON.parse(data);
debug("Got payload", data);
if(data.type == 'kill')
child.kill(data.signal);
});
var child = spawn(...data.query);
var payload = { type : 'pid', pid : child.pid };
debug("ACK pid", payload);
control.write(JSON.stringify(payload));
control.on('data', function(data) {
data = JSON.parse(data);
debug("Got payload", data);
if(data.type == 'kill')
child.kill(data.signal);
['close', 'error', 'exit'].map(function(event) {
child.on(event, function(...args) {
var payload = {type : 'event', event, args};
debug("ACK ", event, payload);
control.write(JSON.stringify(payload));
});
});
['close', 'error', 'exit'].map(function(event) {
child.on(event, function(...args) {
var payload = {type : 'event', event, args};
debug("ACK ", event, payload);
control.write(JSON.stringify(payload));
});
});
if(child.stdin)
remotestdin.pipe(child.stdin);
if(child.stdout)
child.stdout.pipe(remotestdout);
if(child.stderr)
child.stderr.pipe(remotestderr);
};
if(child.stdin)
remotestdin.pipe(child.stdin);
if(child.stdout)
child.stdout.pipe(remotestdout);
if(child.stderr)
child.stderr.pipe(remotestderr);
}
}
module.exports = Server;
"use strict";
const net = require('net');
const guid = () => Math.random().toString(16);
const EventEmitter = require('events');

@@ -16,12 +16,11 @@ const multiplex = require('multiplex');

const createClient = (...remote) => {
const createClient = (stream, readable) => {
const armor = multiplex();
(readable || stream).pipe(armor);
armor.pipe(stream);
return function(...query) {
const lnk = armor.createStream(guid());
const multi = multiplex();
var lnk = net.connect(...remote, function() {
debug('Connected to', ...remote);
});
lnk.pipe(multi);

@@ -61,3 +60,3 @@ multi.pipe(lnk);

lnk.on('close', function() {
stream.on('close', function() {
if(rp._exited)

@@ -64,0 +63,0 @@ return;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc