Merge branch 'Dexus-master'
This commit is contained in:
+10
-2
@@ -3,6 +3,7 @@
|
|||||||
var log = require('winston'),
|
var log = require('winston'),
|
||||||
merge = require('utils-merge'),
|
merge = require('utils-merge'),
|
||||||
net = require('net'),
|
net = require('net'),
|
||||||
|
tls = require('tls'),
|
||||||
session = require('./session');
|
session = require('./session');
|
||||||
|
|
||||||
function login() {
|
function login() {
|
||||||
@@ -94,7 +95,7 @@ function clientSession(sock, options) {
|
|||||||
* @param func callback(err, session)
|
* @param func callback(err, session)
|
||||||
*/
|
*/
|
||||||
function client(options, callback) {
|
function client(options, callback) {
|
||||||
var sock = new net.Socket();
|
var sock;
|
||||||
|
|
||||||
if (typeof options === 'function') {
|
if (typeof options === 'function') {
|
||||||
callback = options;
|
callback = options;
|
||||||
@@ -107,11 +108,18 @@ function client(options, callback) {
|
|||||||
'port': 2775,
|
'port': 2775,
|
||||||
'username': 'user',
|
'username': 'user',
|
||||||
'password': 'pass',
|
'password': 'pass',
|
||||||
|
'tls': false,
|
||||||
'enqLinkTiming': 20000 // 20 sec
|
'enqLinkTiming': 20000 // 20 sec
|
||||||
}, options || {});
|
}, options || {});
|
||||||
|
|
||||||
|
if (options && options.tls && option.tls === true) {
|
||||||
|
sock = new tls.Socket();
|
||||||
|
} else {
|
||||||
|
sock = new net.Socket();
|
||||||
|
}
|
||||||
|
|
||||||
log.debug('larvitsmpp: lib/client.js: client() - Connecting to ' + options.host + ':' + options.port);
|
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);
|
var session = clientSession(sock, options);
|
||||||
|
|
||||||
log.info('larvitsmpp: lib/client.js: client() - Connected to ' + sock.remoteAddress + ':' + sock.remotePort);
|
log.info('larvitsmpp: lib/client.js: client() - Connected to ' + sock.remoteAddress + ':' + sock.remotePort);
|
||||||
|
|||||||
+11
-1
@@ -3,6 +3,7 @@
|
|||||||
var log = require('winston'),
|
var log = require('winston'),
|
||||||
merge = require('utils-merge'),
|
merge = require('utils-merge'),
|
||||||
net = require('net'),
|
net = require('net'),
|
||||||
|
tls = require('tls'),
|
||||||
session = require('./session'),
|
session = require('./session'),
|
||||||
smppUtils = require('./utils');
|
smppUtils = require('./utils');
|
||||||
|
|
||||||
@@ -146,6 +147,8 @@ function serverSession(sock, options) {
|
|||||||
* @param func callback(err, session)
|
* @param func callback(err, session)
|
||||||
*/
|
*/
|
||||||
function server(options, callback) {
|
function server(options, callback) {
|
||||||
|
var tlsOrNet;
|
||||||
|
|
||||||
if (typeof options === 'function') {
|
if (typeof options === 'function') {
|
||||||
callback = options;
|
callback = options;
|
||||||
options = {};
|
options = {};
|
||||||
@@ -154,13 +157,20 @@ function server(options, callback) {
|
|||||||
// Set default options
|
// Set default options
|
||||||
options = merge({
|
options = merge({
|
||||||
'port': 2775,
|
'port': 2775,
|
||||||
|
'tls': false,
|
||||||
'timeout': 40000 // 40 sec
|
'timeout': 40000 // 40 sec
|
||||||
}, options || {});
|
}, options || {});
|
||||||
|
|
||||||
|
if (options && options.tls && option.tls === true) {
|
||||||
|
tlsOrNet = tls;
|
||||||
|
} else {
|
||||||
|
tlsOrNet = net;
|
||||||
|
}
|
||||||
|
|
||||||
// Create a server instance, and chain the listen function to it
|
// Create a server instance, and chain the listen function to it
|
||||||
// The function passed to net.createServer() becomes the event handler for the 'connection' event
|
// The function passed to net.createServer() becomes the event handler for the 'connection' event
|
||||||
// The sock object the callback function receives UNIQUE for each connection
|
// The sock object the callback function receives UNIQUE for each connection
|
||||||
net.createServer(function(sock) {
|
tlsOrNet.createServer(options, function(sock) {
|
||||||
var returnObj = serverSession(sock, options);
|
var returnObj = serverSession(sock, options);
|
||||||
|
|
||||||
// We have a connection - a socket object is assigned to the connection automatically
|
// We have a connection - a socket object is assigned to the connection automatically
|
||||||
|
|||||||
Reference in New Issue
Block a user