I'm trying to connect my NodeJS app to a Oracle DB using SecureGateway but doesn't work.
I executed tests, and when I run
var exec = require('child_process').exec;
var sys = require('sys');
function puts(error, stdout, stderr) { sys.puts(stdout) }
exec("ping 192.168.10.8", puts);
for test my connection, I don't have results. So I think a don't created the connection between my app and my gateway.
When I was running in DataConnect, works normally.
I use require('bluemix-secure-gateway')
for take the informations from my server.
The function that is used for create the tunnel are
const tls = require('tls');
const net = require('net');
var creations = 0; // a running count of the number of open connections, when it becomes 0, the tunnel is closed.
var server; // a server listening for certificate requests from the gateway server
exports.create = function(port, options, callback) {
if(creations == 0) {
creations++;
//server not currently running, create one
server = net.createServer(function (conn) {
connectFarside(conn, options, function(err, socket) {
socket.pipe(conn);
conn.pipe(socket);
});
});
server.listen(port, function(){
callback();
});
} else{
//server already running
creations++;
callback()
}
};
function connectFarside(conn, options, callback) {
try {
var socket = tls.connect(options, function() {
callback(null, socket);
});
socket.on('error', function(err){
console.log('Socket error: ' + JSON.stringify(err));
});
} catch(err) {
callback(err);
}
};
exports.close = function(){
creations--;
if(creations == 0){
// close the server if this was
// the only connections running on it
server.close();
}
}
The result that I have is my local net.