Sender ID Alphanumeric Problem

Dec 14, 2014 at 2:51 PM
There is problem when use alphabetical Plz help me.

TON= Aphanumeric
NPI= UnKnown
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JamaaTech.Smpp.Net.Client;
using JamaaTech.Smpp.Net.Lib;
using System.Threading;
using System.Threading.Tasks;
using System.Net.NetworkInformation;

namespace Mgate_SMS_Gateway
{
    class SMPP
    {

        // -- Ton -- 
        //--------------
        //Unknown = 0,
        //International = 1,
        //National = 2,
        //NetworkSpecific = 3,
        //SubscriberNumber = 4,
        //Aphanumeric = 5,
        //Abbreviated = 6,

        // -- NPI -- 
        //--------------
        //Unknown = 0,
        //ISDN = 1,
        //Data = 3,
        //Telex = 4,
        //LandMobile = 6,
        //National = 8,
        //Private = 9,
        //ERMES = 10,
        //Internet = 14,
        //WapClient = 18,

        private SmppClient client;
        private SmppConnectionProperties properties;
        private Task SendingTask;
        public SMPP(string SystemID, string Password, int Port, string Host,int SourceNPI, int SourceTon,int DestinationNPI,int DestinationTon, int KeepAliveInterval, int AutoReconnectDelay)
        {
            this.SendingTask = new Task(new Action(ConsumingQueue));
            this.client = new SmppClient();
            this.properties = client.Properties;
            properties.SystemID = SystemID;
            properties.Password = Password;
            properties.Port = Port; //IP port to use
            properties.Host = Host; //SMSC host name or IP Address
            properties.InterfaceVersion = InterfaceVersion.v34;
            properties.DefaultEncoding = DataCoding.UCS2;
            properties.AddressNpi = NumberingPlanIndicator.Unknown;
            properties.AddressTon = TypeOfNumber.Aphanumeric;
            //Resume a lost connection after %AutoReconnectDelay% seconds
            client.AutoReconnectDelay = AutoReconnectDelay;
            //Send Enquire Link PDU every %KeepAliveInterval% seconds
            client.KeepAliveInterval = KeepAliveInterval;
            client.MessageReceived += new EventHandler<MessageEventArgs>(client_MessageReceived);
            client.MessageSent+=  new EventHandler<MessageEventArgs>(client_MessageSent);
            client.ConnectionStateChanged += client_ConnectionStateChanged;
            
            
        }

        private void client_ConnectionStateChanged(object sender, ConnectionStateChangedEventArgs e)
        {
            switch (e.CurrentState)
            {
                case SmppConnectionState.Closed:
                    {
                        //Connection to the remote server is lost
                        //Do something here
                        Console.WriteLine("Failed to connect try again .......");
                        e.ReconnectInteval = 7000; //Try to reconnect
                        break;
                    }
                case SmppConnectionState.Connected:
                    {
                        //A successful connection has been established
                        Console.WriteLine(e.PreviousState +" -> Connected");
                        break;
                    }
                case SmppConnectionState.Connecting:
                    {
                        //A connection attemp is still on progress
                        Console.WriteLine("Connecting .......[" + this.properties.Host + "," + this.properties.SystemID + "]");
                            
                        break;
                    }
            }
        }

        internal bool PingServer(string IP)
        {

            bool netOK = false;
            string[] oct = IP.Split(new char[] { '.' });
            byte[] AddrBytes = new byte[] { Convert.ToByte(oct[0].ToString()), Convert.ToByte(oct[1].ToString()), Convert.ToByte(oct[2].ToString()), Convert.ToByte(oct[3].ToString()) }; // byte array for server address.

            using (System.Net.NetworkInformation.Ping png = new System.Net.NetworkInformation.Ping())
            {
                System.Net.IPAddress addr;
                addr = new System.Net.IPAddress(AddrBytes);
                try
                {
                    netOK = (png.Send(addr, 1500, new byte[] { 0, 1, 2, 3 }).Status == IPStatus.Success);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                    netOK = false;
                }
                return netOK;
            }
        }


        public void Close()
        {
            this.client.Shutdown();
        }

        public void Start()
        {
            //Start smpp client
            if (PingServer(this.client.Properties.Host))
            {
                this.client.Start();
                Random Intialization = new Random();
                Thread.Sleep(Intialization.Next(500, 700));
                SendingTask.Start();
            }
            else
            {
                Console.WriteLine("Error // Server is not reachable ... [" + this.properties.Host + "]");
            }
        }

        public SmppConnectionState GetStatus()
        {
            return this.client.ConnectionState;
        }

        // Sending messages
        public void  SendMessage(string MSISDN, string SenderID, string Text)
        {
            if (MSISDN == null || MSISDN == string.Empty) throw new ArgumentNullException("MSISDN");
            if (SenderID == null || SenderID == string.Empty) throw new ArgumentNullException("SenderID");
            if (Text == null || Text == string.Empty) throw new ArgumentNullException("Text");
            TextMessage msg = new TextMessage();
            msg.DestinationAddress = MSISDN; //Receipient number
            msg.SourceAddress = SenderID ; // Sender ID
            msg.RegisterDeliveryNotification = true;
           
            msg.Text = Text;
            try
            {
                if (this.client.ConnectionState == SmppConnectionState.Connected)
                    this.client.SendMessage(msg);
            }
            catch(Exception ex)
            { 
                Console.WriteLine(ex.StackTrace);
            }
            
        }


        //This handler will be called every time we receive a message from a gateway
        public void client_MessageReceived(object sender, MessageEventArgs e)
        {
            //The event argument e contains more information about the received message
            TextMessage textMsg = e.ShortMessage as TextMessage; //This is the received text message
            string msgInfo = string.Format("Sender: {0}, Receiver: {1}, Message content: {2}", textMsg.SourceAddress, textMsg.DestinationAddress, textMsg.Text);
            //Display message
            Console.WriteLine(msgInfo);
        }

        public void client_MessageSent(object sender, MessageEventArgs e)
        {

            Console.WriteLine("Done->>"+e.ShortMessage.ToString());  
            
        }
        private void ConsumingQueue()
        {
            try
            {
                Random r = new Random();
                Thread.Sleep(r.Next(1000, 3000));
                Console.WriteLine("Start Sending Task .......["+this.properties.Host+","+this.properties.SystemID+"]");

                //while(true){
                SendMessage("966567898825", "Pension", "this is test: " + r.Next());
                    
                //}
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }


    }
}