Add TLS Support

This commit is contained in:
Josef Fröhle
2016-06-22 22:06:09 +02:00
parent d5dbd74af2
commit aaf93273c5
2 changed files with 122 additions and 107 deletions
+9 -2
View File
@@ -3,6 +3,7 @@
var log = require('winston'),
merge = require('utils-merge'),
net = require('net'),
tls = require('tls'),
session = require('./session');
function login() {
@@ -94,7 +95,6 @@ function clientSession(sock, options) {
* @param func callback(err, session)
*/
function client(options, callback) {
var sock = new net.Socket();
// Set default options
options = merge({
@@ -102,11 +102,18 @@ function client(options, callback) {
'port': 2775,
'username': 'user',
'password': 'pass',
'tls': false,
'enqLinkTiming': 20000 // 20 sec
}, options || {});
if(options && options.tls && option.tls === true){
var sock = new tls.Socket();
} else {
var sock = new net.Socket();
}
log.debug('larvitsmpp: lib/client.js: client() - Connecting to ' + options.host + ':' + options.port);
sock.connect(options.port, options.host, function() {
sock.connect(options, function() {
var session = clientSession(sock, options);
log.info('larvitsmpp: lib/client.js: client() - Connected to ' + sock.remoteAddress + ':' + sock.remotePort);