messageid concept

Post Reply
htin
Posts: 13
Joined: Wed Aug 07, 2019 9:01 am

messageid concept

Post by htin » Tue Aug 13, 2019 7:16 pm

I am not sure how the messageId works. it is generated by SMPP server or client. ?
if the messageId is initially set by client then How to get messageId from in submitSm event handler (server api).?

if messageid is set by server then how can i set messageid in submitsmResponse so that client can keep track of messageId.

I am actually implementing smpp server/proxy/geteway where clients can connects and send messages and get delivery reports

Also if clients sends submitMultiSm.then how is the messageid works?

please point me the right direction. thanks in advance.
alt
Site Admin
Posts: 767
Joined: Tue Apr 25, 2006 9:45 am

Re: messageid concept

Post by alt » Wed Aug 14, 2019 5:43 am

MessageId is generated on the server side. When server receives SubmitSm or SubmitMulti PDU it generates corresponding response and sets MessageId.
You can change MessageId property in evClientSubmitSm and evClientSubmitMulti event handlers:

Code: Select all

private void ServerOnClientSubmitSm(object sender, SmppServerClient client, SubmitSm data)
{
    data.Response.MessageId = Guid.NewGuid().ToString().Substring(0, 8);
}
htin
Posts: 13
Joined: Wed Aug 07, 2019 9:01 am

Re: messageid concept

Post by htin » Wed Aug 14, 2019 6:50 am

here is a sample test

Code: Select all

//submitsm handler
  private async void SubmitSmHandler(object sender, SmppServerClient serverClient, SubmitSm data)
        {
		//send message through other external sms provider
		//get message id from external provider 
		
		//log shows correct messageId from provider
		 _log.Info("message id :" + messageIdFromExternalProvider);
		 //set it here
		 data.Response.MessageId = messageIdFromExternalProvider;
		 


my test client

Code: Select all

		var submitResp = await client.Submit(
                            SMS.ForSubmit()
                                .From("1234")
                                .To("9595049344")
                                .Coding(DataCodings.UCS2)
                                .Text("messagetexthere").DeliveryReceipt());
                        
                        if (submitResp.All(x => x.Header.Status == CommandStatus.ESME_ROK))
                        {
                        	//messageid is from somewhere which i dont even know, but definitely not mine
                             _log.Info("Message has been sent."+submitResp[0].MessageId);
                        }

or am I retreiving messageId wrong from my test client? if so, how?
alt
Site Admin
Posts: 767
Joined: Tue Apr 25, 2006 9:45 am

Re: messageid concept

Post by alt » Wed Aug 14, 2019 8:43 am

Your code looks correct. I cannot reproduce this issue in my tests.

Which library version are you using now?

Could you post here log records for this test case?
htin
Posts: 13
Joined: Wed Aug 07, 2019 9:01 am

Re: messageid concept

Post by htin » Wed Aug 14, 2019 10:47 am

I am using the latest one 2.6.12
I have my server running on my local machine.
then i launch my client using vsstudio on my mac

here are my client codes

Code: Select all

 static void Main(string[] args)
        {
            Console.WriteLine("smpp client!");
            //ClientSubmitSMUnicode().Wait();
            Task result = ClientSubmitSMUnicode();
            result.Wait();
            Console.ReadLine();

        }
        
        public static async Task ClientSubmitSMUnicode()
        {
            
            using (client = new SmppClient())
            {
                 
                		client.EnabledSslProtocols = SslProtocols.Tls12;
                		client.evServerCertificateValidation += OnServerCertificateValidation;
				client.evDisconnected += new DisconnectedEventHandler(client_evDisconnected);
				client.evDeliverSm += new DeliverSmEventHandler(client_evDeliverSm);
				client.evEnquireLink += new EnquireLinkEventHandler(client_evEnquireLink);
				client.evUnBind += new UnBindEventHandler(client_evUnBind);
				client.evDataSm += new DataSmEventHandler(client_evDataSm);
				client.evRecoverySucceeded += ClientOnRecoverySucceeded;
               			 client.ConnectionRecovery = true;
				client.EnabledSslProtocols = SslProtocols.Tls12;

				_messageComposer = new MessageComposer();
                		_messageComposer.evFullMessageReceived += OnFullMessageReceived;
                		_messageComposer.evFullMessageTimeout += OnFullMessageTimeout;

                if (await client.Connect("localhost", 2775).ConfigureAwait(false))
                {
                    BindResp bindResp = await client.Bind("wavemoney", "pwwd135");
                    
                    if (bindResp.Header.Status == CommandStatus.ESME_ROK)
                    {
                        
                        var submitResp = await client.Submit(
                            SMS.ForSubmit()
                                .From("1234")
                                .To("123456")
                                .Coding(DataCodings.UCS2)
                                .Text("testmessage").DeliveryReceipt());

                        if (submitResp.All(x => x.Header.Status == CommandStatus.ESME_ROK))
                        {
                            //getting old messageId instead of new messageId set by server why?
                            Console.WriteLine("Message has been sent. " + submitResp[0].MessageId);
                        }

                    }
                     

                    //await client.Disconnect();
                }
            }
        }

my server code

Code: Select all

private async void SubmitSmHandler(object sender, SmppServerClient serverClient, SubmitSm data)
        {
             //check the messageid from client
             _log.Info("messageid from client :" + data.Response.MessageId); 
            if (user != null)
            {
                 
                ExternalMessageApiResponse msgResponse = await  SendMessageThroughExternalHttpApi();
                 
                _log.Info("message id :" + msgResponse.messageId);
                //assign custom message id
                data.Response.MessageId = msgResponse.messageId;
                //check if the new messageid is set
                _log.Info("after set in server, data.Response.MessageId :" + data.Response.MessageId);
                 
                if (data.RegisteredDelivery == 1)
                {
                    _log.Info("DLR requested");
                    //Send Delivery Receipt when required
                    await serverClient.Deliver(
                        SMS.ForDeliver()
                            .From(data.SourceAddress)
                            .To(data.DestinationAddress)
                            .Coding(data.DataCoding)
                            .Receipt(new Receipt
                            {
                                DoneDate = DateTime.Now,
                                State = MessageState.Undeliverable,//just for testing
                                MessageId = data.Response.MessageId, //set the messageID for dlr
                                ErrorCode = "0",
                                SubmitDate = DateTime.Now
                            }
                            )
                    )
                    .ConfigureAwait(false);
                }
                else
                {
                    _log.Info("DLR not requested");
                }


            }
            

            _log.Info("after sent numbers of connected clients :" + _server.ConnectedClients.Count);
        }

This is very rough idea what I am trying to do.
1. accept client connections,
2. from submitsm events send sms through other external api and get messageid from external api.
3. get delivery report from api then send it back to client using the same messageid

here are my issues
1. how can i make the client alive and still connected to server.
2. so i can send deliverysm to clients whenever i receive from external api
3. I may have been messed up by async/await junks.

any help would be appreciated. I am in urgent need.

Thanks in advance
htin
Posts: 13
Joined: Wed Aug 07, 2019 9:01 am

Re: messageid concept

Post by htin » Wed Aug 14, 2019 11:08 am

this is the log from your HelloWorld Sample client connected to my server and I capture the logs

Code: Select all

14.08.2019 17:34:25:INFO :  4: (SmppClient1.Socket) 127.0.0.1:50348 => InterNetwork/localhost:2775 Connection established.
14.08.2019 17:34:25:DEBUG:  8: (SmppClient1) Send PDU: BindTransceiver, Sequence: 1
14.08.2019 17:34:25:TRACE:  8: (SmppClient1.Socket) Sending data: Length=39, 000000........................4000000
14.08.2019 17:34:25:TRACE: 12: (SmppClient1.Socket) Received data: Length=29, 00000..............................5000
14.08.2019 17:34:25:DEBUG:  3: (SmppClient1) PDU Received: BindTransceiverResp, Status: ESME_ROK, Sequence: 1, SystemId: Inetlab.SMPP
14.08.2019 17:34:25:DEBUG:  8: (SmppClient1) Send PDU: SubmitSm, Status: ESME_ROK, Sequence: 2, SourceAddr: 111, DestAddr: 95......44
14.08.2019 17:34:25:TRACE:  8: (SmppClient1.Socket) Sending data: Length=84, 00000......................005d
14.08.2019 17:34:25:TRACE: 12: (SmppClient1.Socket) Received data: Length=53, 000000........................646500
14.08.2019 17:34:25:DEBUG:  3: (SmppClient1) PDU Received: SubmitSmResp, Status: ESME_ROK, Sequence: 2, MessageId: a897e61f-b9bc-417b-8e85-36430b56f3de
14.08.2019 17:34:25:INFO :  5: (SmppClient1) Message has been sent. a897e61f-b9bc-417b-8e85-36430b56f3de
14.08.2019 17:34:25:DEBUG:  3: (SmppClient1.Socket) 127.0.0.1:50348 => InterNetwork/localhost:2775 Start disconnecting.
14.08.2019 17:34:25:DEBUG:  3: (SmppClient1.Socket) 127.0.0.1:50348 => InterNetwork/localhost:2775 Shutdown Send.
14.08.2019 17:34:25:DEBUG:  3: (SmppClient1.Socket) 127.0.0.1:50348 => InterNetwork/localhost:2775 Wait until receive is finished.
14.08.2019 17:34:25:DEBUG: 12: (SmppClient1.Socket) 127.0.0.1:50348 => InterNetwork/localhost:2775 Remote side has dropped connection.
14.08.2019 17:34:25:DEBUG: 12: (SmppClient1.Socket) 127.0.0.1:50348 => InterNetwork/localhost:2775 Shutdown Receive.
14.08.2019 17:34:25:DEBUG:  3: (SmppClient1.Socket) 127.0.0.1:50348 => InterNetwork/localhost:2775 Connection closed.

I modified this line to print the messageId from my server but apparently not correct messageid from my server
14.08.2019 17:34:25:INFO : 5: (SmppClient1) Message has been sent. a897e61f-b9bc-417b-8e85-36430b56f3de
alt
Site Admin
Posts: 767
Joined: Tue Apr 25, 2006 9:45 am

Re: messageid concept

Post by alt » Wed Aug 14, 2019 2:30 pm

When you use async await in EventHandler it doesn't work as you expecting.

Library doesn't see changes after await. It raises event handler synchronously and after that sends response to the client. In your event handler library sends a response before calling await function.

Try to set message id before await call.
htin
Posts: 13
Joined: Wed Aug 07, 2019 9:01 am

Re: messageid concept

Post by htin » Thu Aug 15, 2019 2:04 am

Thank you, I got it working. I have one question though
if the server do not set this messageId, client set this before request?

Code: Select all

data.Response.MessageId
i.e .
If i print it out before the server set this. there is already a value in there. how set this ? client?


My intention is to give our clients an option to provide their own messageId or get the messageId generated by server.


Thanks
Post Reply