Connecting To An SMSC

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 5

Connecting to an SMSC

Create an SmppClient instance SmppClient client = new SmppClient(); Then provide connection details by populating the SmppClient.Properties property SmppConnectionProperties properties = client.Properties; properties.SystemID = "mysystemid"; properties.Password = "mypassword"; properties.Port = 2034; //IP port to use properties.Host = "196.23.3.12"; //SMSC host name or IP Address properties.SystemType = "mysystemtype"; properties.DefaultServiceType = "mydefaultservicetype"; //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(); Additionally, you can handle the SmppClient.ConnectionStateChanged event to receive notifications when connection status changes

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 e.ReconnectInteval = 60000; //Try to reconnect after 1 min break; case SmppConnectionState.Connected: //A successful connection has been established break; case SmppConnectionState.Connecting: //A connection attemp is still on progress break; } }
Last edited Apr 17 2011 at 3:12 AM by bentesha, version 1

Comments
codexer Aug 2 2011 at 1:35 AM

@SparkyUK: The mentioned lib works!! I just tested this and I was able to send the message with alphanumeric sender. the message has been delivered and all semms to be OK. Here ist the way you can use it: ..... SmppClient mmclient = new SmppClient(); // init he client SubmitSm mSubmitSM = new SubmitSm(); // init the submitsm method

//Populate SubmitSm properties as required mSubmitSM.SourceAddress.Address = "IchSendeWas"; // alphanumeric sender mSubmitSM.DestinationAddress.Address = "49123456789"; // destination MSISDN mSubmitSM.DestinationAddress.Npi = NumberingPlanIndicator.Unknown; // destionation NPI mSubmitSM.DestinationAddress.Ton = TypeOfNumber.Unknown; // destionation TON mSubmitSM.SourceAddress.Npi = NumberingPlanIndicator.Unknown; // source NPI mSubmitSM.SourceAddress.Ton = TypeOfNumber.Aphanumeric; // and here the important setting: TON - 5 (alphanumeric) - works for me :-) mSubmitSM.EsmClass = EsmClass.Default; // esm class mSubmitSM.RegisteredDelivery = RegisteredDelivery.DeliveryReceipt; //reg_del to 1 mSubmitSM.ServiceType = "CMT"; // service type cellular messaging, - not mandatory to set, you can leave it mSubmitSM.SetMessageText("@", DataCoding.SMSCDefault); // send msg - all OK, message received on handset with Sender "IchSendeWas" regards Codexer
SparkyUK Jul 4 2011 at 7:36 AM

Some networks in the UK require a correct TON setting. Currently, 'Net.Lib.TypeOfNumber.Aphanumeric' doesn't appear to work. Any chance this could be fixed? If an invalid TON is used, the message is not delivered on some networks. I am setting this, as such: client.Properties.AddressTon = Net.Lib.TypeOfNumber.Aphanumeric
Fasasisparks Apr 24 2011 at 2:11 AM

With the connection details, i believe i was able to connect to the SMSC server successfully Sign in to add a comment

Sending & Receiving Messages


Note: This article explains sending messages synchronously using Jamaa SMPP Client library. For more information about sending messages asynchronously, please read this guide Sending Messages Asynchronously Before you can send/receive messages, you must first connect to an SMSC. For more information on how to connect to an SMSC, read this guide Connecting to an SMSC Sending messages TextMessage msg = new TextMessage(); msg.DestinationAddress = "255455388333"; //Receipient number msg.SourceAddress = "255344338333"; //Originating number msg.Text = "Hello, this is my test message!"; msg.RegisterDeliveryNotification = true; //I want delivery notification for this message SmppClient client = GetSmppClient(); client.SendMessage(msg); Note: Beta 1 release does not support concatenated messages. In this case you must limit the number of characters to not more than 160. Receiving messages

To receive messages, handle the SmppClient.MessageReceived event as follows: SmppClient client = GetSmppClient(); client.MessageReceived += client_MessageReceived; private void client_MessageReceived(object sender, MessageEventArgs e) { TextMessage msg = e.ShortMessage as TextMessage; MessageBox.Show(msg.Text); //Display message }
Last edited Apr 17 2011 at 4:07 AM by bentesha, version 2 lay Jan 31 at 5:32 PM

Comments

This code can sent message but when sent Unicode it not support ( not support Unicode) why?, can you help me, like as sent message Thai front to mobile( support Thai language)
lay Jan 31 at 5:28 PM

mmSubmitSm = new SubmitSm(); // instance of the SubmitSm mmSubmitSm.ServiceType = "CMT"; // cellular messaging 'CMT' //mmSubmitSm.RegisteredDelivery = RegisteredDelivery.DeliveryReceipt; // MT delivered? wanna know... :-) report SMS to customer mmSubmitSm.EsmClass = EsmClass.Default; // leave it default at the moment... mmSubmitSm.DestinationAddress.Address = "8888888888"; // destination mmSubmitSm.DestinationAddress.Npi = NumberingPlanIndicator.Unknown; // known settings mmSubmitSm.DestinationAddress.Ton = TypeOfNumber.Unknown; // known settings mmSubmitSm.SourceAddress.Npi = NumberingPlanIndicator.Unknown; // known settings mmSubmitSm.SourceAddress.Ton = TypeOfNumber.Unknown; // known settings mmSubmitSm.SourceAddress.Address = "1444"; mmSubmitSm.SetMessageText(textBox2.Text.Trim(),DataCoding.UCS2); // message content with coding mmSubmitSmResp = mmSession.SendPdu(mmSubmitSm) as SubmitSmResp; // send PDU textBox1.Text = mmSubmitSmResp.MessageID + "\n"; // show message ID Report SMS to SMSC textBox1.Text = textBox1.Text + mmSubmitSmResp.Header.ErrorCode.ToString() + "\n"; // any error code there? No, all went OK :-) MessageBox.Show(mmSubmitSmResp.Header.ErrorCode.ToString());
mikemo85 Dec 8 2011 at 4:12 AM codexer Aug 2 2011 at 1:33 AM

I just want to receive messages. Do I need to specify the DestinationAddress? You don't need to use the code segment: SmppClient client = GetSmppClient(); Please use this: public partial class Form1 : Form // initialize this in the "public partial class Form1 : Form" and you will have the posibility to use it in your project { SmppClient myclient = new SmppClient(); .... .... // othe code segments .... // send message: myclient.SendMessage("Hallo there!")
Fasasisparks Apr 24 2011 at 2:14 AM

how do i reference GetSmppClient()...it doesnt seems to be part of the Dlls provided. i changed it to SMPPClient but received an error message on client.SendMessage(msg) Object reference not set to an instance of an object. How do i correct this? Sign in to add a comment

Sending Messages Asynchronously


For more information about receiving and sending messages synchronously, follow this guide Sending & Receiving Messages Before you can start sending messages, you must first connect to an SMSC. For more information about connecting to an SMSC, read this guide Connecting to an SMSC Sending messages asynchronously Jamaa Smpp Client provides an asynchronous version of the SendMessage method for sending messages asynchronously without waiting for the operation to complete. The following code snippet shows how to send message asynchronously. TextMessage msg = new TextMessage(); //set msg properties SmppClient client = GetSmppClient(); client.BeginSendMessage(msg, SendMessageCompleteCallback, client); //continue with other stuff Below is a method that will be called after the asynchronous operation completes: private void SendMessageCompleteCallback(IAsyncResult result) { SmppClient client = (SmppClient)result.AsyncState; client.EndSendMessage(result); }
Last edited Apr 17 2011 at 4:28 AM by bentesha, version 2

Receiving Delivery Notifications


Warning: The message content for delivery notifications may differ between network operators. Jamaa Smpp Client delivers all notifications as simple text messages, and you must parse out the message content yourself to extract any additional information. Because the message format can differ, there is good change that you code will break when dealing with a situation in which more than one network operator is involved. As such, the use of delivery notifications is normally not advised in most scenarios. To receive delivery notification, handle the SmppClient.MessageDelivered event as follows: SmppClient client = GetSmppClient(); client.MessageDelivered += client_MessageDelivered;

The event handler: void client_MessageDelivered(object sender, MessageEventArgs e) { TextMessage msg = e.ShortMessage as TextMessage; //parse msg.Text for more details MessageBox.Show(msg.Text, "Message Delivered"); }
Last edited Apr 17 2011 at 4:46 AM by bentesha, version 2

Comments No comments yet.

Support for Concatenated Messages


As of Beta 1 Release, support for concatenated messages is not included. Out going messages which are more than 160 characters in length will cause an exception to be thrown. Incoming message with more than 160 characters will be split into 160-characters segments. To know if a message is part of a concatenated message, use the ShortMessage.MessageCount property as follows: if(msg.MessageCount > 1) { /*This is part of a concatenated message*/ } You can write your own code to concatenate segments of a concatenated message using the ShortMessage.SegmentID and ShortMessage.SequenceNumber properties. All segments of a given concatenated message will have the same SegmentID value while the SequenceNumber indicates the index of a segment in a concatenated message and ranges from 1 to MessageCount property value.
Last edited Apr 17 2011 at 5:01 AM by bentesha, version 2

Comments No comments yet. Sign in to add a comment

Multi-Threading Issues
When using Jamaa Smpp Client, it is important to keep in mind that all events provided by the SmppClient class are invoked by arbitrary threads from the thread pool. As such it is possible for an event handler to be invoked by more than one thread concurrently which may result into unpredictable outcomes or data corruptions. You must therefore ensure that all SmppClient event handlers, and other methods accessible from the event handlers are thread-safe.
Last edited Apr 17 2011 at 5:18 AM by bentesha, version 3

Comments

You might also like