Created
February 14, 2011 03:26
-
-
Save postwait/825441 to your computer and use it in GitHub Desktop.
sample use of tls in node.js v0.4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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