farhadi / node-smpp

SMPP client and server implementation in node.js
MIT License
418 stars 177 forks source link

SMPP Session - Not Allow Re-connection #90

Closed mseld closed 5 years ago

mseld commented 5 years ago

I am asking you if you can add new feature to allow session reconnect considering is session unbind/closed or even tcp socket closed

ritmas commented 5 years ago

I would suggest using process control system, like Supervisor, which will ensure your process / node is up & running. Once socket is unintentionally unbinded/closed, Supervisor restarts it.

mseld commented 5 years ago

Hello @ritmas
i'm already use pm2 as process manager but i need to keep service a live even connection is dropped and try to establish connection again because i need to fail over to another provider after number of trails

ritmas commented 5 years ago

I've tested pm2 recently, as it was new for me, but I couldn't reproduce the case once connection is dropped from server side and client wouldn't able to reconnect - it always rebind successfully, at least in my case. @mseld could you share exact error code / test scenario which fails client to reconnect/rebind?

My test case: initiated random session.close(); from server side, but client is keep rebinding:

PM2 > App [client:0] starting in -fork mode-
PM2 > App [client:0] online
client > client: connected
client > client: binded
client > client: socket closed
PM2 > App [client:0] exited with code [0] via signal [SIGINT]
PM2 > App [client:0] starting in -fork mode-
PM2 > App [client:0] online
client > client: connected
client > client: binded
mseld commented 5 years ago

Hello @ritmas there's no problem in pm2 to do like this functionality that you mention in previous comment. What i need it different , i need to implement fail-over strategy when smpp client can't connect to provider after number of trails it should use different connection.

ritmas commented 5 years ago

Have you tried the following?

var smpp = require('smpp'),
    // used '127.0.0.2' intentionally so to mimic cannot-connect case
    session = smpp.connect('127.0.0.2', 2775);

// info: https://nodejs.org/api/net.html#net_socket_settimeout_timeout_callback
session.socket.setTimeout(1000);
session.socket.on('timeout', function() {
    console.log('socket timeout');
    session.destroy();
});
juliangut commented 5 years ago

@mseld it's been more than 2 months from last response, did you find it useful? did you solved your problem?

mseld commented 5 years ago

@juliangut Yes i find the way to solve this case using below code

session.socket.on('close', function(had_err) {
    setTimeout(() => {
        session.connect();
        session.resume();
    }, 1000);
});
juliangut commented 5 years ago

Tnaks for the aswer @mseld , closing this issue

elhananjair commented 8 months ago

@juliangut @mseld Thank you guys for the solution, I was looking for this,

But I am getting this warning in the terminal:

(node:37152) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 connect listeners added to [Socket]. Use emitter.setMaxListeners() to increase limit