//Changes in conection private void client_ConnectionStateChanged(object sender, ConnectionStateChangedEventArgs e) { switch (e.CurrentState) { case SmppConnectionState.Closed: //Connection to the remote server is lost //Do something here Library.WriteErrorLog("Connection to the remote server is lost"); e.ReconnectInteval = 60000; //Try to reconnect after 1 min attempts = attempts + 1; if (attempts >= 3) { client.Shutdown(); timer1.Enabled = false; Library.WriteErrorLog("Service Stopped"); } break; case SmppConnectionState.Connected: //A successful connection has been established Library.WriteErrorLog("Connection SMPP Client (" + client.Properties.SystemID + ") Started"); timer1 = new Timer(); this.timer1.Interval = 20000; //20 segundos this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(this.timer_connection); timer1.Enabled = true; //Sending Messages msg.DestinationAddress = numReceipient; //Receipient number msg.SourceAddress = numOriginating; //Originating number msg.Text = textMessage; msg.RegisterDeliveryNotification = true; //I want delivery notification for this message client.SendMessage(msg, 1000); Library.WriteErrorLog("Message Sent Successfully! Receipient number:" + numReceipient + "Message:" + textMessage); break; case SmppConnectionState.Connecting: //A connection attemp is still on progress Library.WriteErrorLog("A connection attemp is still on progress"); break; } }
static void Main(string[] args) { SmppConnectionProperties properties = client.Properties; properties.SystemID = "XXX"; properties.Password = "******"; properties.Port = 5050; properties.Host = "XX.XXX.X.XXX"; properties.SourceAddress = "XXXXXXXXXX"; properties.DefaultEncoding = DataCoding.UCS2; //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(); client.ConnectionStateChanged += Client_ConnectionStateChanged; client.MessageSent += Client_MessageSent; while (client.ConnectionState != SmppConnectionState.Connected) { Thread.Sleep(100); } var msg = new TextMessage(); Console.Write("Please enter your phone number: "); msg.DestinationAddress = "XXXXXXXXXXXX"; msg.SourceAddress = "XXXXXXXXXX"; msg.Text = "سلام"; msg.RegisterDeliveryNotification = true; client.SendMessage(msg); Console.ReadLine(); }
private static void SendMessage(string command) { var parts = command.Split(' '); var dest = parts[1]; var msgTxt = string.Join(" ", parts, 2, parts.Length - 2); if (string.IsNullOrEmpty(msgTxt)) { msgTxt = @"السلام عليكم ورحمة الله وبركاته هذه رسالة عربية متعددة الاسطر"; } TextMessage msg = new TextMessage(); msg.DestinationAddress = dest; //Receipient number msg.SourceAddress = smppConfig.SourceAddress; //Originating number //msg.Text = "Hello, this is my test message!"; msg.Text = msgTxt; msg.RegisterDeliveryNotification = true; //I want delivery notification for this message msg.UserMessageReference = GenerateUserMessageReference(smppConfig.UserMessageReferenceType); _Log.DebugFormat($"msg.UserMessageReference: {msg.UserMessageReference}"); try { client.SendMessage(msg); } catch (SmppException smppEx) { _Log.ErrorFormat("smppEx.ErrorCode:({0}) {1} ", (int)smppEx.ErrorCode, smppEx.ErrorCode); _Log.Error(smppEx); } catch (Exception e) { _Log.Error("SendMessage:" + e.Message, e); } //client.BeginSendMessage(msg, SendMessageCompleteCallback, client); }