Merge branch 'master' of https://github.com/Dexus/larvitsmpp into Dexus-master
This commit is contained in:
+9
-2
@@ -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();
|
||||
|
||||
if (typeof options === 'function') {
|
||||
callback = options;
|
||||
@@ -107,11 +107,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);
|
||||
|
||||
+9
-1
@@ -3,6 +3,7 @@
|
||||
var log = require('winston'),
|
||||
merge = require('utils-merge'),
|
||||
net = require('net'),
|
||||
tls = require('tls'),
|
||||
session = require('./session'),
|
||||
smppUtils = require('./utils');
|
||||
|
||||
@@ -154,13 +155,20 @@ function server(options, callback) {
|
||||
// Set default options
|
||||
options = merge({
|
||||
'port': 2775,
|
||||
'tls': false,
|
||||
'timeout': 40000 // 40 sec
|
||||
}, options || {});
|
||||
|
||||
if(options && options.tls && option.tls === true){
|
||||
var tls_or_net = tls;
|
||||
} else {
|
||||
var tls_or_net = net;
|
||||
}
|
||||
|
||||
// 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 sock object the callback function receives UNIQUE for each connection
|
||||
net.createServer(function(sock) {
|
||||
tls_or_net.createServer(options, function(sock) {
|
||||
var returnObj = serverSession(sock, options);
|
||||
|
||||
// We have a connection - a socket object is assigned to the connection automatically
|
||||
|
||||
Reference in New Issue
Block a user