1. How to connect to SMPP server

    For connecting to SMPP server you need to get username and password from your mobile network operator.

    CopyC#
    SmppClient client = new SmppClient();
    client.Connect("smpp.server.com", 7777);
    if (client.Status == ConnectionStatus.Open) 
    {
        Logger.Write("Connected to SMPP server");
        client.Bind("username", "password");
        if (client.Status == ConnectionStatus.Bound) 
        { 
           Logger.Write("Bound with SMPP server");
        }
    }

    In Bind method you can specify ConnectionMode. There are 3 modes you can use:

    1. Transmitter - allows to send short messages to the SMSC and to receive the corresponding SMPP responses from the SMSC

    2. Receiver - allows to send short messages to receive short messages from the SMSC and to return the corresponding SMPP message responses to the SMSC

    3. Transceiver - allows to send messages to the SMSC and receive messages from the SMSC over a single SMPP session.

    Default ConnectionMode is Transceiver.

  2. How to send SMS

    For sending simple SMS message you can use fluent SMS builder:

    CopyC#
    Client.Submit(SMS.ForSubmit()
         .ServiceType("test")
         .Text("Test Test Test Test Test Test Test Test Test Test")
         .From("1111")
         .To("2222")
         .DeliveryReceipt()
         .Coding(DataCodings.Default)
         );

    or the same message with old style:

    CopyC#
    SubmitSm sm = new SubmitSm();
    sm.ServiceType = "test";
    sm.UserDataPdu.ShortMessage = Client.GetMessageBytes("Test Test Test Test Test Test Test Test Test Test", DataCodings.Default);
    sm.SourceAddr = "1111";
    sm.SourceAddrTon = 0;
    sm.SourceAddrNpi = 1;
    sm.DestAddr = "2222";
    sm.DestAddrTon = 0;
    sm.DestAddrNpi = 1;
    sm.DataCoding = DataCodings.Default;
    sm.RegisteredDelivery = 1;
    
    Client.Submit(sm);

    There is only one difference. First code allows you to send text with any length, but second code only up to 160 symbols.

  3. How to get delivery receipt

    In order to request delivery receipt from SMSC you need to set property SubmitSm..::..RegisteredDelivery to 1.

    CopyC#
    sm.RegisteredDelivery = 1;
  4. How to receive delivery receipt from SMSC

    SMSC returns delivery receipt in the DELIVER_SM message. In order to receive these messages you need to attach to the event evDeliverSm

    CopyC#
    client.evDeliverSm += new Broadnet.Common.DeliverSmEventHandler(client_evDeliverSm);

    In case when propery DeliverSm..::..MessageType equils to MessageTypes..::..SMSCDeliveryReceipt client received delivery receipt. The informational content of an SMSC Delivery Receipt can be retrieved from property Receipt.

    CopyC#
    private void client_evDeliverSm(object sender, Broadnet.PDU.DeliverSm data)
    {
        if (data.MessageType == Broadnet.Common.MessageTypes.SMSCDeliveryReceipt)
        {
            string messageId = data.Receipt.MessageId;
        }
    }
    Tip

    This messageId is the same that returned by the SMSC in SubmitSmResp..::..MessageId

  5. How to combine concatenated DeliverSm messages

    As well as SubmitSm messages longer than 140 bytes will be submitted as concatenated parts, DeliverSm messages from SMSC can be split on parts too. You can use Broadnet.Common..::..MessageComposer class to combine all parts into full text message.

    CopyC#
    private readonly MessageComposer _composer = new MessageAssembler();
    
    private void client_evDeliverSm(object sender, DeliverSm data)
    {
    
        Concatenation concatenation = data.Concatenation;
    
        // Receive incoming message and try to concatenate all parts
        if (concatenation != null)
        {
    
            _composer.AddMessage(data);
    
            string messageText = data.Client.GetMessageText(data);
    
            AddToLog("DeliverSm part received : "
                     + " Sequence : " + data.Sequence
                     + " SourceAddr : " + data.SourceAddr
                     + " Concatenation ( " + concatenation+ " )"
                     + " Coding : " + data.DataCoding
                     + " Text : " + messageText);
    
    
            if (_composer.IsLastSegment(data))
            {
    
                string fullMessage = _composer.GetFullMessage(data);
    
                AddToLog("Full message text: " + fullMessage);
            }
    
        }
    
    }
  6. How to send one message to destinations list

    SubmitMulti command allows to send one message to several destination addresses.

    Note

    Sometimes SMSC doesn't support this command, please clarify before use

    CopyC#
    List<DestinationAddress> destList = new List<DestinationAddress>();
    
    DestinationAddress da1 = new DestinationAddress();
    da1.Address = "11111111111";
    da1.Npi = 0;
    da1.Ton = 1;
    destList.Add(da1);
    
    DestinationAddress da2 = new DestinationAddress();
    da2.Address = "22222222222";
    da2.Npi = 0;
    da2.Ton = 1;
    destList.Add(da2);
    
    Client.SubmitAsync(SMS.ForSubmitMulti()
         .ServiceType("test")
         .Text("Test Test Test Test Test Test Test Test Test Test")
         .From("MyService")
         .ToDestinations(destList)
         .DeliveryReceipt()
         );

    or you can use several chained To methods

    CopyC#
    Client.SubmitAsync(SMS.ForSubmitMulti()
      .ServiceType("test")
      .Text("Test Test Test Test Test Test Test Test Test Test")
      .From("MyService")
      .To("11111111111")
      .To("22222222222")
      .DeliveryReceipt()
      );
  7. How to trace transfered PDU between client and SMPP server

    Since version 1.1 Broadnet uses Broadnet.Logging..::..ILog interface for logging. In SmppClientDemo application you can find example class TextBoxLogger that implements ILog interface. When you need logging of Broadnet classes you need to register logger when your application starts.

    CopyC#
    LogManager.SetLoggerFactory(delegate(string loggerName)
                                       {
                                           return new TextBoxLogger(tbLog, loggerName);
                                       });

    When you need to trace network stream of SMPP protocol your logger class should implement method Trace()()()().

    Also you can use two events for tracking PDU objects received from remote endpoint evPduReceiving or submitted from local evPduSending.

  8. How to handle Throttling error from SMSC

    SMSC can limit number of submitted PDU for SMPP account. When allowed message limit exceeded, server returns status ESME_RTHROTTLED. To avoid throttling error you can specify number of messages per second in SmppClient. For this purpose you can set property SendSpeedLimit

    CopyC#
    //Send 10 messages per second
    client.SendSpeedLimit = 10;
    
    //Send 1 message every 5 seconds
    client.SendSpeedLimit = 1f/5f;
  9. How to change encoding for SMPP data_coding

    For each SmppClient instance you can define what Encoding will be used for specified DataCodings.

    CopyC#
    //Set GSM Packed Encoding for data_coding Latin1 (0x3)
    client.MapEncoding(DataCodings.Latin1, new Broadnet.Encodings.GSMPackedEncoding());

    By default SmppClient has following data_coding to Encoding mappings:

    CopyC#
    MapEncoding(DataCodings.Default, new Broadnet.Encodings.GSMEncoding());
    MapEncoding(DataCodings.UCS2, System.Text.Encoding.BigEndianUnicode);
    MapEncoding(DataCodings.UnicodeFlashSMS, System.Text.Encoding.BigEndianUnicode);