55 lines
1013 B
JavaScript
55 lines
1013 B
JavaScript
|
|
// Require some libraries
|
|
var proxysocket = require("proxysocket");
|
|
var net = require("net");
|
|
|
|
// Set the first varible
|
|
var first = true;
|
|
|
|
// Setup the proxy varible
|
|
var proxy;
|
|
|
|
// Wait for a message from the client
|
|
process.on('message', function(data)
|
|
{
|
|
// Is this the first time called
|
|
if(first)
|
|
{
|
|
// Set first
|
|
first = false;
|
|
|
|
// Parse the data
|
|
data = JSON.parse(data);
|
|
|
|
// Connect to the proxy
|
|
proxy = proxysocket.create(data.proxy.host, data.proxy.port);
|
|
|
|
// Start a connection
|
|
proxy.connect(data.connect.port, data.connect.host, function()
|
|
{
|
|
// Send a status message
|
|
process.send("connected");
|
|
|
|
// Wait for data from the proxy
|
|
proxy.on("data", function(data)
|
|
{
|
|
// Send the data to the client
|
|
process.send(data);
|
|
});
|
|
})
|
|
}
|
|
|
|
else
|
|
{
|
|
// Send the data to the proxy
|
|
proxy.write(Buffer(data));
|
|
}
|
|
});
|
|
|
|
// Has the parent been killed
|
|
process.on('disconnect', function()
|
|
{
|
|
// Exit
|
|
process.exit();
|
|
});
|