Skip to content

Commit

Permalink
Merge branch 'add-tls'
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicholas Terrell committed Feb 12, 2016
2 parents 982bb00 + e51a803 commit 96d0241
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions lib/smpp.js
@@ -1,4 +1,5 @@
var net = require('net'),
tls = require('tls'),
util = require('util'),
defs = require('./defs'),
PDU = require('./pdu').PDU,
Expand All @@ -8,6 +9,7 @@ function Session(options) {
EventEmitter.call(this);
options = options || {};
var self = this;
var transport = net;
this.sequence = 0;
this.paused = false;
this._busy = false;
Expand All @@ -17,7 +19,10 @@ function Session(options) {
} else {
this.port = options.port;
this.host = options.host;
this.socket = net.connect(this.port, this.host);
if (options.isTls) {
transport = tls;
}
this.socket = transport.connect(this.port, this.host);
this.socket.on('connect', function() {
self.emit('connect');
});
Expand Down Expand Up @@ -124,7 +129,7 @@ for (var command in defs.commands) {
}

function Server() {
var options, self = this;
var options, transport, self = this;
this.sessions = [];

if (typeof arguments[0] == 'function') {
Expand All @@ -137,7 +142,13 @@ function Server() {
}
}

net.Server.call(this, options, function(socket) {
if (options.key && options.cert) {
transport = tls;
} else {
transport = net;
}

transport.Server.call(this, options, function(socket) {
var session = new Session({socket: socket});
session.server = self;
self.sessions.push(session);
Expand All @@ -148,7 +159,7 @@ function Server() {
});
}

util.inherits(Server, net.Server);
util.inherits(Server, tls.Server);

Server.prototype.listen = function() {
var args = [2775];
Expand All @@ -157,17 +168,18 @@ Server.prototype.listen = function() {
} else if (arguments.length > 0) {
args = arguments;
}
return net.Server.prototype.listen.apply(this, args);
return tls.Server.prototype.listen.apply(this, args);
};

exports.createServer = function() {
return new Server(arguments[0], arguments[1]);
};

exports.connect = exports.createSession = function(host, port) {
exports.connect = exports.createSession = function(host, port, isTls) {
return new Session({
host: host || 'localhost',
port: port || 2775 // Default SMPP port is 2775
port: port || 2775, // Default SMPP port is 2775
isTls: isTls || false
});
};

Expand Down

0 comments on commit 96d0241

Please sign in to comment.