farhadi / node-smpp

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

Client not Connected #226

Open AmarKhoirudin opened 1 year ago

AmarKhoirudin commented 1 year ago

Hello i use node-smpp to create server.

when I use the client from node-smpp it succeeds in bind_transceiver but when the client from ActiveXpert Messagging the monitor server doesn't want to connect, the error failed to bind server, timeout. Please help me where did I go wrong??

image

let getSession = [];

var server = smpp.createServer( { debug: true, // debugListener: function (type, msg, payload) { // console.log({ type: type, msg: msg, payload: payload }); // }, }, function (session) { if (typeof session.client !== "undefined") { session.send( pdu.response({ command_status: smpp.ESME_RBINDFAIL, }) ); session.close(); throw Error('Session already has "client" key'); } session["client"] = { system_id: "", };

session.on("error", function (err) {
  console.log(err.code);
  // Something ocurred, not listening for this event will terminate the program
});
session.on("bind_transceiver", function (pdu) {
  // we pause the session to prevent further incoming pdu events,
  // untill we authorize the session with some async operation.
  session.pause();
  checkAsyncUserPass(pdu.system_id, pdu.password, function (err) {
    if (err) {
      session.send(
        pdu.response({
          command_status: smpp.ESME_RBINDFAIL,
        })
      );
      session.close();
      return;
    }
    console.log("ini pdu : ", pdu);
    session.client.system_id = pdu.system_id;
    getSession.push({
      session,
      system_id: pdu.system_id,
    });
    session.send(
      pdu.response({
        system_id: pdu.system_id,
      })
    );
    session.resume();
  });
});

session.on("submit_sm", async function (pdu) {
  console.log("client username is : ", session.client.system_id);
  let msgid = Date.now().toString();
  try {
    console.log(pdu.short_message);
    const send = await insertMessage(
      `Insert into message_send_smpp (pesan, Nomor_hp, user_id, chanel, reference_smpp, in_out) VALUE ('${pdu.short_message.message}', '${pdu.destination_addr}', '${session.client.system_id}', 'gondrong','${msgid}', '0')`
    );
    session.send(
      pdu.response({
        message_id: msgid,
        sequence_number: pdu.sequence_number,
      }),
      (...d) => {
        // console.log("pdu response callback", d);
      }
    );
  } catch (e) {
    console.log(e);
    var s_addr = pdu.source_addr;
    var d_addr = pdu.destination_addr;
    session.send(
      new smpp.PDU("deliver_sm", {
        short_message: `id:${msgid} sub:001 dlvrd:000 submit date:2023/02/15 19:20:39 done date:2023/02/15 19:20:39 stat:REJECTD err:000 textError:Gagal`,
        command_id: 4,
        command_status: "",
        sequence_number: pdu.sequence_number,
        service_type: "",
        source_addr_ton: "",
        source_addr_npi: "",
        source_addr: s_addr,
        dest_addr_ton: 1,
        dest_addr_npi: 1,
        destination_addr: d_addr,
        esm_class: 4,
        protocol_id: 1,
        priority_flag: 1,
        schedule_delivery_time: "",
        validity_period: "",
        registered_delivery: 1,
        replace_if_present_flag: "",
        sm_default_msg_id: "",
      })
    );
  }
  //   if (pdu.registered_delivery) {
  //     // console.log('pdu deliver_sm', pdu);
  //     // await delaySleep(1000);
  //     try {
  //       var s_addr = pdu.source_addr;
  //       var d_addr = pdu.destination_addr;
  //       session.send(
  //         new smpp.PDU("deliver_sm", {
  //           //   message_id: msgid,
  //           //   esm_class: 4,
  //           //   message_state: "DELIVERED",
  //           //   dlvrd: 1,
  //           //   //   short_message: pdu.short_message,
  //           //   source_addr: pdu.destination_addr,
  //           //   destination_addr: pdu.source_addr,
  //           //   sequence_number: pdu.sequence_number + 1,
  //           short_message: `id:${msgid} sub:001 dlvrd:000 submit date:2023/02/15 19:20:39 done date:2023/02/15 19:20:39 stat:DELIVRD err:000 text:63272386`,
  //           command_id: 4,
  //           command_status: "",
  //           sequence_number: pdu.sequence_number,
  //           service_type: "",
  //           source_addr_ton: "",
  //           source_addr_npi: "",
  //           source_addr: s_addr,
  //           dest_addr_ton: 1,
  //           dest_addr_npi: 1,
  //           destination_addr: d_addr,
  //           esm_class: 4,
  //           protocol_id: 1,
  //           priority_flag: 1,
  //           schedule_delivery_time: "",
  //           validity_period: "",
  //           registered_delivery: 1,
  //           replace_if_present_flag: "",
  //           sm_default_msg_id: "",
  //         })
  //       );
  //     } catch (e) {
  //       console.log(e);
  //     }
  //   }
});

} );

AmarKhoirudin commented 1 year ago
image

sorry my question above was successful because tls, how to connect with tls? and I have another new question

when the client disconnects and connects again the error is like the one pictured above, what's the solution?