Skip to content

Instantly share code, notes, and snippets.

@postwait
Created February 14, 2011 03:26
Show Gist options
  • Save postwait/825441 to your computer and use it in GitHub Desktop.
Save postwait/825441 to your computer and use it in GitHub Desktop.
sample use of tls in node.js v0.4
nc.prototype.start = function(conncb) {
var parent = this;
this.conncb = conncb;
this.socket = tls.connect(this.port,this.host,this.creds,
function() {
if(parent.socket.authorized == false) {
sys.puts('invalid cert: ' + parent.socket.authorizationError);
throw('invalid cert: ' + parent.socket.authorizationError);
}
parent.conncb(parent);
}
);
this.socket.addListener('error', function(e) { sys.puts(e); });
this.socket.addListener('close',
function() {
if(parent.socket.authorized == false) sys.puts('invalid cert');
if(!parent.shutdown) {
if(parent.socket) parent.socket.destroy();
parent.socket = null;
setTimeout(function() { parent.start(parent.conncb); }, 1000);
}
}
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment