ShadowNode

Use Node.js in your end devices(QQ: 796448809)

View the Project on GitHub yodaos-project/ShadowNode

TLS/SSL

ShadowNode provides asynchronous TLS/SSL networking module. You can use this module with require('tls') and create clients.

tls.connect(options[, connectListener])

Creates a new tls.TLSSocket and automatically connects with the supplied options. The options object specifies the following information:

Others extend from net.Socket’s options.

Example


var tls = require('tls');
var port = 443;

var secureSocket = tls.connect({
  port: port, 
  host: 'www.google.com'
}, function() {
  secureSocket.end('GET / HTTP/1.1\r\n\r\n');
});

var response = '';
secureSocket.on('data', function(data) {
  response += data;
});

secureSocket.on('end', function() {
  console.log(response);
});

Class: tls.TLSSocket

This object is an abstraction of a TLS socket.

socket.destroy()

Ensures that no more I/O activity happens on the socket and destroys the socket as soon as possible.

socket.end([data][, callback])

Half-closes the socket. The socket is no longer writable. If data is given it is equivalent to socket.write(data) followed by socket.end().

socket.write(data[, callback])

Sends data on the socket.

The optional callback function will be called after the given data is flushed through the connection.

Event: ‘connect’

Emitted after connection is established.

Event: ‘close’

Emitted when the socket has been closed.

Event: ‘data’

Example


var tls = require('tls');
var socket = tls.connect({host: 'www.google.com', port: 443});
var msg = '';

/* ... */

socket.on('data', function(data) {
  msg += data;
});

Event: ‘end’

Emitted when FIN packet received.

Event: ‘error’

Emitted when an error occurs.