Tuesday, November 5, 2013

SMPP Client Program Using Jamaa SMPP Client

the following code working for SMPP request using jamaa smpp library.
download dss from the following link
https://jamaasmpp.codeplex.com/releases/view/65964

then create new windows application or console application and paste the following code and change you SMSC provider data
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using JamaaTech.Smpp.Net.Client;
using JamaaTech.Smpp.Net.Lib;
using JamaaTech.Smpp.Net.Lib.Protocol;

namespace SMPP_Test
{
    public partial class Form1 : Form
    {
        SmppClient mmclient = new SmppClient();
        SmppConnectionProperties mmproperties;
        TextMessage mymsg = new TextMessage();
        public Form1()
        {
            InitializeComponent();
            mmproperties = mmclient.Properties;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            mmproperties.SystemID = "YourSystemID";
            mmproperties.Password = "YourPassword";
            mmproperties.Port = 23651; //IP port to use
            mmproperties.Host = "xxx.net"; //SMSC host name or IP Address
            mmproperties.SystemType = "";
         

            //Resume a lost connection after 30 seconds
            mmclient.AutoReconnectDelay = 3000;
            //Send Enquire Link PDU every 30 seconds
            mmclient.KeepAliveInterval = 30000;
            //Start smpp client
          
           // mmclient.Connect
            mmclient.Properties.InterfaceVersion = InterfaceVersion.v34;
            mmclient.Properties.DefaultEncoding = DataCoding.SMSCDefault;
            mmclient.Properties.SourceAddress = "MadinaWater";
            mmclient.Properties.AddressNpi = NumberingPlanIndicator.Unknown;
            mmclient.Properties.AddressTon = TypeOfNumber.Unknown;
            mmclient.Properties.SystemType = "transceiver";
            mmclient.Properties.DefaultServiceType = ServiceType.DEFAULT;// "transceiver";      
            
            mmclient.MessageReceived += mmclient_MessageReceived;
            mmclient.MessageDelivered += mmclient_MessageDelivered;
            mmclient.MessageSent += mmclient_MessageSent;


            mymsg.DestinationAddress = "+966562824865"; //Receipient number
            mymsg.SourceAddress = "ShortCodeRelated Your Provider"; //Originating number
            mymsg.Text = "Hello, this is my simple client test message!";
            mymsg.RegisterDeliveryNotification = true; //I want delivery notification for this message
         
            mmclient.Start();
            if(mmclient.ConnectionState != SmppConnectionState.Connected )
                mmclient.ForceConnect(5000);
            mmclient.SendMessage(mymsg,1000);
           

            //Provide a handler for the SmppClient.MessageReceived event
          
            mmclient.Shutdown();
           
            ////Resume a lost connection after 30 seconds
            //client.AutoReconnectDelay = 3000;
            ////Send Enquire Link PDU every 15 seconds
            //client.KeepAliveInterval = 15000;

            ////Start smpp client
            //client.Start();
            //TextMessage msg = new TextMessage();
            //msg.DestinationAddress = "+966562824865";
            //msg.Text = "تجربة الإرسال من ال SMPP";
            //msg.SourceAddress = "MWater";
            //client.SendMessage(msg,3000);
           


        }

        void mmclient_MessageSent(object sender, MessageEventArgs e)
        {

            JamaaTech.Smpp.Net.Client.TextMessage textMsg = e.ShortMessage as JamaaTech.Smpp.Net.Client.TextMessage;
            MessageBox.Show(textMsg.Text);

            TextMessage msg = e.ShortMessage as TextMessage;
            string SegID = msg.SegmentID.ToString(); //Gives the message ID from the SMPP on Send 
            string Seg = msg.SequenceNumber.ToString(); //Give the status of the message - Enroute

            MessageBox.Show(msg.Text); //Display message

        }

        void mmclient_MessageDelivered(object sender, MessageEventArgs e)
        {
            JamaaTech.Smpp.Net.Client.TextMessage textMsg = e.ShortMessage as JamaaTech.Smpp.Net.Client.TextMessage;
            MessageBox.Show(textMsg.Text);
           
        }

        void mmclient_MessageReceived(object sender, MessageEventArgs e)
        {
            //The event argument e contains more information about the received message       

            JamaaTech.Smpp.Net.Client.TextMessage textMsg = e.ShortMessage as JamaaTech.Smpp.Net.Client.TextMessage; //This is the received text message                  

           //richTextBox1.Text = richTextBox1.Text + textMsg + " Step 1";
            
            string msgInfo = string.Format("Sender: {0}, Receiver: {1}, Message content: {2}", textMsg.SourceAddress, textMsg.DestinationAddress, textMsg.Text);

            //Display message             MessageBox.Show(msgInfo);       

            //     richTextBox1.Text = richTextBox1.Text + msgInfo;

        }
    }
}

6 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Sir,

    I am getting an exception on the following line:

    "mmclient.SendMessage(mymsg,1000);"

    An SMPP exception is thrown with the error code 148.

    Kindly help ASAP.

    Regards,

    M. Jawad

    ReplyDelete
  4. Sir,

    I resolved the exception and error code 148 issue. It was due to the number format given in the destination address line, which is the following one:

    mymsg.DestinationAddress = "+92333-------";

    After removing the '+' sign, and entering the number as follows: "92333-------", the application started working properly.

    Thank you for your support.

    Regards,
    M. Jawad Saleem

    ReplyDelete
  5. Hi, A long-term and Experienced SMPP gateway provider yields a positive impact on the company or organization. SMPP Client Panel

    ReplyDelete
  6. Many time I am receiving ESME_TimeOut exception and then it disconnect client till retry connection time given. Have you ever receve this type of exception? If yes then have you found any solution for that.
    Please guide me.

    ReplyDelete