Send message from Server to Client

.NET library for SMPP protocol
Locked
DerSkythe
Posts: 11
Joined: Tue Oct 09, 2012 7:12 am

Send message from Server to Client

Post by DerSkythe » Thu Aug 29, 2013 7:34 am

Hello, I want to send message from server to client.
With documentation I found 2 ways to do that: send delivery_sm or data_sm.
For example:

Code: Select all

var rec = Receipt.Create(Encoding.ASCII.GetBytes("Hello, this is test message"), Encoding.ASCII);
                        var deliver = new DeliverSm
                        {
                            Receipt = rec,
                            SourceAddrTon = (byte)Ton.Unknown,
                            SourceAddrNpi = (byte)Npi.ISDN,
                            SourceAddr = "994503312380",
                            DestAddrTon = (byte)Ton.Unknown,
                            DestAddrNpi = (byte)Npi.ISDN,
                            DestAddr = "8145",
                            RegisteredDelivery = (byte)SMSCDeliveryReceipt.NotRequested,
                            DataCoding = DataCodings.Default,
                            EsmClass = (byte)MessageTypes.Default
                        };
But client received:
12:27:36: Received Data: 00-00-00-69-00-00-00-05-00-00-00-00-50-2C-2A-53-00-00-01-39-39-34-35-30-33-33-31-32-33-38-30-00-00-01-38-31-34-35-00-04-00-00-00-00-00-00-00-00-38-69-64-3A-20-73-75-62-3A-30-30-30-20-64-6C-76-72-64-3A-30-30-30-20-73-75-62-6D-69-74-20-64-61-74-65-3A-20-64-6F-6E-65-20-64-61-74-65-3A-20-73-74-61-74-3A-20-65-72-72-3A
12:27:36: DeliverSm received : Sequence : 1345071699 SourceAddr : 994503312380 Coding : Default MessageText : id: sub:000 dlvrd:000 submit date: done date: stat: err:

How can I send the correct message, out of "id", "sub" and others?
alt
Site Admin
Posts: 918
Joined: Tue Apr 25, 2006 9:45 am

Re: Send message from Server to Client

Post by alt » Mon Sep 02, 2013 2:21 pm

Hello DerSkythe,

With this code you send to client delivery receipt. You need this when you need to notify client that his sms message has been delivered.
Don't set Receipt property when you want to send ordinal message.

Possible this link helps also
http://www.inetlab.com/wiki/doku.php/smpp/server
DerSkythe
Posts: 11
Joined: Tue Oct 09, 2012 7:12 am

Re: Send message from Server to Client

Post by DerSkythe » Tue Sep 03, 2013 5:50 am

In the link that you provided you use another library.
I can't provide to Deliver method class different from DeliverSm.
There is no property Text in DeliverSm class.
My version of library 1.0.12.10. Please tell me, how can I solve the problem?

Code: Select all

  [Serializable]
  public class DeliverSm : SmppPDU, ISerializable
  {
    [MethodImpl(MethodImplOptions.NoInlining)]
    public DeliverSm();
    [MethodImpl(MethodImplOptions.NoInlining)]
    protected DeliverSm(SerializationInfo info, StreamingContext context);
    [MethodImpl(MethodImplOptions.NoInlining)]
    public static byte[] Serialize(DeliverSm deliver);
    [MethodImpl(MethodImplOptions.NoInlining)]
    public static DeliverSm Deserialize(byte[] data);
    [MethodImpl(MethodImplOptions.NoInlining)]
    void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context);
    [MethodImpl(MethodImplOptions.NoInlining)]
    public DeliverSm Clone();
    public DeliverSmResp Response { [MethodImpl(MethodImplOptions.NoInlining)] get; [MethodImpl(MethodImplOptions.NoInlining)] set; }
    public Receipt Receipt { [MethodImpl(MethodImplOptions.NoInlining)] get; [MethodImpl(MethodImplOptions.NoInlining)] set; }
    public byte EsmClass { [MethodImpl(MethodImplOptions.NoInlining)] get; [MethodImpl(MethodImplOptions.NoInlining)] set; }
    public string ServiceType { [MethodImpl(MethodImplOptions.NoInlining)] get; [MethodImpl(MethodImplOptions.NoInlining)] set; }
    public byte SourceAddrTon { [MethodImpl(MethodImplOptions.NoInlining)] get; [MethodImpl(MethodImplOptions.NoInlining)] set; }
    public byte SourceAddrNpi { [MethodImpl(MethodImplOptions.NoInlining)] get; [MethodImpl(MethodImplOptions.NoInlining)] set; }
    public string SourceAddr { [MethodImpl(MethodImplOptions.NoInlining)] get; [MethodImpl(MethodImplOptions.NoInlining)] set; }
    public byte DestAddrTon { [MethodImpl(MethodImplOptions.NoInlining)] get; [MethodImpl(MethodImplOptions.NoInlining)] set; }
    public byte DestAddrNpi { [MethodImpl(MethodImplOptions.NoInlining)] get; [MethodImpl(MethodImplOptions.NoInlining)] set; }
    public string DestAddr { [MethodImpl(MethodImplOptions.NoInlining)] get; [MethodImpl(MethodImplOptions.NoInlining)] set; }
    public DataCodings DataCoding { [MethodImpl(MethodImplOptions.NoInlining)] get; [MethodImpl(MethodImplOptions.NoInlining)] set; }
    public ushort MessageReferenceNumber { [MethodImpl(MethodImplOptions.NoInlining)] get; }
    public byte TotalSegments { [MethodImpl(MethodImplOptions.NoInlining)] get; }
    public byte SegmentNumber { [MethodImpl(MethodImplOptions.NoInlining)] get; }
    public UserData UserDataPdu { [MethodImpl(MethodImplOptions.NoInlining)] get; [MethodImpl(MethodImplOptions.NoInlining)] set; }
    public MessageModes MessageMode { [MethodImpl(MethodImplOptions.NoInlining)] get; [MethodImpl(MethodImplOptions.NoInlining)] set; }
    public MessageTypes MessageType { [MethodImpl(MethodImplOptions.NoInlining)] get; [MethodImpl(MethodImplOptions.NoInlining)] set; }
    public GSMSpecificFeatures MessageFeature { [MethodImpl(MethodImplOptions.NoInlining)] get; }
    public SMSCDeliveryReceipt SMSCReceipt { [MethodImpl(MethodImplOptions.NoInlining)] get; [MethodImpl(MethodImplOptions.NoInlining)] set; }
    public SMEAcknowledgement Acknowledgement { [MethodImpl(MethodImplOptions.NoInlining)] get; [MethodImpl(MethodImplOptions.NoInlining)] set; }
    public IntermediateNotification Notification { [MethodImpl(MethodImplOptions.NoInlining)] get; [MethodImpl(MethodImplOptions.NoInlining)] set; }
    public TLVCollection Optional { [MethodImpl(MethodImplOptions.NoInlining)] get; }
    public byte[] PacketBytes { [MethodImpl(MethodImplOptions.NoInlining)] get; }
    public byte ProtocolId { [MethodImpl(MethodImplOptions.NoInlining)] get; [MethodImpl(MethodImplOptions.NoInlining)] set; }
    public byte PriorityFlag { [MethodImpl(MethodImplOptions.NoInlining)] get; [MethodImpl(MethodImplOptions.NoInlining)] set; }
    public byte RegisteredDelivery { [MethodImpl(MethodImplOptions.NoInlining)] get; [MethodImpl(MethodImplOptions.NoInlining)] set; }
  }

  public sealed class SmppServerClient : SmppClientBase
  {
    [MethodImpl(MethodImplOptions.NoInlining)]
    public SmppServerClient();
    [MethodImpl(MethodImplOptions.NoInlining)]
    protected override SmppPDU ProcessSmppMessage(SmppPDU packet);
    [MethodImpl(MethodImplOptions.NoInlining)]
    public void DeliverAsync(DeliverSm data);
    [MethodImpl(MethodImplOptions.NoInlining)]
    public DeliverSmResp Deliver(DeliverSm data);
    public byte InterfaceVersion { [MethodImpl(MethodImplOptions.NoInlining)] get; [MethodImpl(MethodImplOptions.NoInlining)] set; }
    public ConnectionMode BindingMode { [MethodImpl(MethodImplOptions.NoInlining)] get; [MethodImpl(MethodImplOptions.NoInlining)] set; }
    public event BindEventHandler evBind;
    public event OutBindEventHandler evOutBind;
    public event SubmitSmEventHandler evSubmitSm;
    public event SubmitMultiEventHandler evSubmitMulti;
    public event QuerySmEventHandler evQuerySm;
    public event CancelSmEventHandler evCancelSm;
  }

  [Serializable]
  public abstract class SmppPDU
  {
    protected SmppClientBase _client;
    [MethodImpl(MethodImplOptions.NoInlining)]
    public SmppPDU();
    [MethodImpl(MethodImplOptions.NoInlining)]
    public SmppPDU(CommandSet command);
    [MethodImpl(MethodImplOptions.NoInlining)]
    public SmppPDU(CommandSet command, CommandStatus status);
    [MethodImpl(MethodImplOptions.NoInlining)]
    public override string ToString();
    public SmppClientBase Client { [MethodImpl(MethodImplOptions.NoInlining)] get; }
    public uint Length { [MethodImpl(MethodImplOptions.NoInlining)] get; [MethodImpl(MethodImplOptions.NoInlining)] set; }
    public CommandSet Command { [MethodImpl(MethodImplOptions.NoInlining)] get; [MethodImpl(MethodImplOptions.NoInlining)] set; }
    public CommandStatus Status { [MethodImpl(MethodImplOptions.NoInlining)] get; [MethodImpl(MethodImplOptions.NoInlining)] set; }
    public uint Sequence { [MethodImpl(MethodImplOptions.NoInlining)] get; [MethodImpl(MethodImplOptions.NoInlining)] set; }
  }
alt
Site Admin
Posts: 918
Joined: Tue Apr 25, 2006 9:45 am

Re: Send message from Server to Client

Post by alt » Fri Sep 06, 2013 11:11 am

please give a try two following ways

Code: Select all

           // Create DeliverSm with text in ShortMessage field
            var deliverInUserData = new DeliverSm
            {
                SourceAddrTon = (byte)Ton.Unknown,
                SourceAddrNpi = (byte)Npi.ISDN,
                SourceAddr = "994503312380",
                DestAddrTon = (byte)Ton.Unknown,
                DestAddrNpi = (byte)Npi.ISDN,
                DestAddr = "8145",
                DataCoding = DataCodings.Default,
                EsmClass = (byte)MessageTypes.Default,
                UserDataPdu = new UserData
                                  {
                                      ShortMessage = client.GetMessageBytes("Hello, this is test message", DataCodings.Default)
                                  }
            };

            // or in MessagePayload field

            var deliverInPayload = new DeliverSm
            {
                SourceAddrTon = (byte)Ton.Unknown,
                SourceAddrNpi = (byte)Npi.ISDN,
                SourceAddr = "994503312380",
                DestAddrTon = (byte)Ton.Unknown,
                DestAddrNpi = (byte)Npi.ISDN,
                DestAddr = "8145",
                DataCoding = DataCodings.Default,
                EsmClass = (byte)MessageTypes.Default,
                Optional = new TLVCollection
                              {
                                  new TLV(OptionalTags.MessagePayload, client.GetMessageBytes("Hello, this is test message", DataCodings.Default))
                              }
            };
DerSkythe
Posts: 11
Joined: Tue Oct 09, 2012 7:12 am

Re: Send message from Server to Client

Post by DerSkythe » Mon Sep 09, 2013 6:52 am

Solution with UserDataPdu works for me. Thank you very much.
Locked