0

I am trying to build an SMS an SMS Client using NodeJS which should connect to ``Inetlab ```` SMPP Server to send Short messages. I downloaded Inetlab SMPP client and Server and run them both. When I try to connect and send an SMS from the client via port 7777 (Not that it matters), The connection is bound successfully and the message is sent across.

My problem is when I try connect to the same local SMPP server via a client that I have bult with NodeJS using the node-smpp library, the connection fails even though I am using the same localhost and port 7777.

Below is my connection code:


module.exports = class{

    constructor(){
       this.session = null
       this.smppConfig = {
            url:"smpp://localhost:7777",
            auto_enquire_link_period:10000,
            debug:true
       }
    }

    StartSmppSession= ()=>{
        return new Promise( async(resolve, reject)=>{
            try{
                    console.log(this.smppConfig)
                    this.session = smpp.connect(this.smppConfig,()=>{
                        this.session.bind_transceiver({
                            system_id:process.env.SMPP_SYSTEM_ID,
                            password:process.env.SMPP_PASSWORD
                        },(pdu)=>{
                            if(pdu.command_status === 0){
                                resolve({message:"Connection bound successfully!"})
                            }else{
                                reject({message:"Failed to bind!",pdu})
                            }
                        })
                })
            }catch(err){
                //reject(err.message)
            }
        })
    }

    sendSMS = (payload)=>{
        return new Promise(async (resolve, reject)=>{
            try{
                //payload = {destination_addr:"phone_number", "short_message":"The message here"}
                this.session.submit_sm(payload, async (pdu)=>{
                    pdu.command_status === 0 ? resolve("Message successfully sent!") : reject("Failed to send SMS!")
                })
            }catch(err){
                reject(err.message)
            }
        })
    }
}


When I invoke the StartSmppSession() function in my controller, I get the following error log:

2022-12-06T09:30:40.973Z - cli - 315644 - socket.error - connect ECONNREFUSED ::1:7777 - {"errno":-4078,"code":"ECONNREFUSED","syscall":"connect","address":"::1","port":7777}
node:events:491
      throw er; // Unhandled 'error' event
      ^

Error: connect ECONNREFUSED ::1:7777
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1284:16)
Emitted 'error' event on Session instance at:
    at Socket.<anonymous> (C:\Users\c.mwale\Desktop\NRB API Test\Notifications Module\SMSGateway\src\SMS_Outgoing\node_modules\smpp\lib\smpp.js:119:8)
    at Socket.emit (node:events:513:28)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -4078,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '::1',
  port: 7777
}

I understand that there is a SMPP library for .NET documented on the inetlab website, but I am of the view this the intent of using a C# example was not to dictate the framework nor language of implementation.

CliffTheCoder
  • 394
  • 1
  • 4
  • 24

0 Answers0