public USSDSample(SmppClient client) { _client = client; TLVCollection.RegisterParameter <UssdServiceOpParameter>(0x0501); _client.evDeliverSm += OnMessageReceivedFromMS; }
public AnSmppClient(string hostName, int port, IAnBind anBind) { this.hostName = hostName; this.port = port; this.anBind = anBind; client = new SmppClient(); }
public async Task <string> Send(string from, string to, string message) { var conf = new Conf(); conf.host = "0.0.0.0"; //это хост смпп сервера conf.port = 0000; //это порт смпп сервера conf.systemId = "test"; //это логин или системный ид смпп позователя conf.password = "******"; //это парол смпп позователя SmppClient client = new SmppClient(); await client.Connect(conf.host, conf.port); await client.Bind(conf.systemId, conf.password, ConnectionMode.Transceiver); var resp = await client.Submit( SMS.ForSubmit() .From(from, AddressTON.Alphanumeric, AddressNPI.Unknown) .To(to, AddressTON.International, AddressNPI.ISDN) .Coding(DataCodings.Cyrllic) .Text(message) ); if (resp.All(x => x.Header.Status == CommandStatus.ESME_ROK)) { return("Message has been sent."); } return(resp.GetValue(0).ToString()); }
// <SendHelloWorld> public static async Task SendHelloWorld() { using (SmppClient client = new SmppClient()) { if (await client.Connect("192.168.1.190", 7777)) { BindResp bindResp = await client.Bind("admin", "admin"); if (bindResp.Header.Status == CommandStatus.ESME_ROK) { var submitResp = await client.Submit( SMS.ForSubmit() .From("111") .To("222") .Coding(DataCodings.UCS2) .Text("Hello dude!!")); if (submitResp.All(x => x.Header.Status == CommandStatus.ESME_ROK)) { client.Logger.Info("Message has been sent."); } } // await client.Disconnect(); } } }
static SmppClient CreateSmppClient(ISmppConfiguration config) { var client = new SmppClient(); client.Name = config.Name; //client.SmppEncodingService = new SmppEncodingService(System.Text.Encoding.UTF8); client.ConnectionStateChanged += new EventHandler <ConnectionStateChangedEventArgs>(client_ConnectionStateChanged); client.StateChanged += new EventHandler <StateChangedEventArgs>(client_StateChanged); client.MessageSent += new EventHandler <MessageEventArgs>(client_MessageSent); client.MessageDelivered += new EventHandler <MessageEventArgs>(client_MessageDelivered); client.MessageReceived += new EventHandler <MessageEventArgs>(client_MessageReceived); SmppConnectionProperties properties = client.Properties; properties.SystemID = config.SystemID; // "mysystemid"; properties.Password = config.Password; // "mypassword"; properties.Port = config.Port; // 2034; //IP port to use properties.Host = config.Host; // "196.23.3.12"; //SMSC host name or IP Address properties.SystemType = config.SystemType; // "mysystemtype"; properties.DefaultServiceType = config.DefaultServiceType; // "mydefaultservicetype"; properties.DefaultEncoding = config.Encoding; //Resume a lost connection after 30 seconds client.AutoReconnectDelay = config.AutoReconnectDelay; //Send Enquire Link PDU every 15 seconds client.KeepAliveInterval = config.KeepAliveInterval; return(client); }
// <SendHelloWorld> public static async Task SendHelloWorld() { using (SmppServer server = new SmppServer(new IPEndPoint(IPAddress.Any, 7777))) { server.Start(); using (SmppClient client = new SmppClient()) { if (await client.Connect("localhost", 7777)) { BindResp bindResp = await client.Bind("1", "2"); if (bindResp.Header.Status == CommandStatus.ESME_ROK) { var submitResp = await client.Submit( SMS.ForSubmit() .From("111") .To("222") .Coding(DataCodings.UCS2) .Text("Hello World!")); if (submitResp.All(x => x.Header.Status == CommandStatus.ESME_ROK)) { client.Logger.Info("Message has been sent."); } } await client.Disconnect(); } } } }
public static async Task SendSubmitSmWithUDH(SmppClient client) { //If you have UserDataHeader as byte array. You can create SubmitSm manually and pass it to headers collection. byte[] udh = new byte[] { 5, //UDHL, 0, //Concatenation 3, // Length 50, //message reference 1, //total parts, 1, // part number }; SubmitSm sm = new SubmitSm(); sm.SourceAddress = new SmeAddress("My Service"); sm.DestinationAddress = new SmeAddress("+7917123456"); sm.DataCoding = DataCodings.UCS2; sm.RegisteredDelivery = 1; sm.UserData.ShortMessage = client.EncodingMapper.GetMessageBytes("test message", sm.DataCoding); sm.UserData.Headers = udh; var resp = await client.Submit(sm); }
public static void Initialize() { smppClient = new SmppClient(); smppClient.Timeout = 4000; smppClient.NeedEnquireLink = true; smppClient.EnquireInterval = 5; smppClient.SendSpeedLimit = 50; smppClient.RaiseEventsInMainThread = true; }
public static async Task SendText(SmppClient client) { var resp = await client.Submit( SMS.ForSubmit() .From("short_code") .To("436641234567") .Coding(DataCodings.UCS2) .Text("test text") ); }
public static async Task SendMessageToApplicationPort(SmppClient client) { var resp = await client.Submit( SMS.ForSubmit() .From("short_code") .To("436641234567") .Text("test") .Set(sm => sm.UserData.Headers.Add(new ApplicationPortAddressingScheme16bit(0x1579, 0x0000))) ); }
/// <summary> Serialize SubmitSm object to the byte array. </summary> /// /// <param name="client"> The client. </param> /// <param name="pdu"> The SubmitSm object. </param> /// /// <returns> A byte array. </returns> public byte[] Serialize(SmppClient client, SubmitSm pdu) { using (MemoryStream stream = new MemoryStream()) { using (SmppWriter writer = new SmppWriter(stream, client.EncodingMapper)) { writer.WritePDU(pdu); return(stream.ToArray()); } } }
private static void SendMessageCompleteCallback(IAsyncResult result) { try { SmppClient client = (SmppClient)result.AsyncState; client.EndSendMessage(result); } catch (Exception e) { Trace.TraceError("SendMessageCompleteCallback:" + e.ToString()); } }
private static void SendMessageCompleteCallback(IAsyncResult result) { try { SmppClient client = (SmppClient)result.AsyncState; client.EndSendMessage(result); } catch (Exception e) { _Log.Error("SendMessageCompleteCallback:" + e.Message, e); } }
public static async Task SendBinary(SmppClient client) { byte[] data = ByteArray.FromHexString( "FFFF002830006609EC592F55DCE9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005C67"); var resp = await client.Submit( SMS.ForSubmit() .From("short_code") .To("436641234567") .Data(data) ); }
public async Task <DataSmResp> SendDataSm(SmppClient client, string text) { DataSm dataSm = new DataSm(); dataSm.SourceAddress = new SmeAddress("1111"); dataSm.DestinationAddress = new SmeAddress("79171234567"); dataSm.DataCoding = DataCodings.UCS2; byte[] data = client.EncodingMapper.GetMessageBytes(text, dataSm.DataCoding); dataSm.Parameters.Add(new MessagePayloadParameter(data)); return(await client.SubmitData(dataSm)); }
public SMPPGateway() { _proxyServer = new SmppServer(new IPEndPoint(IPAddress.Any, 7776)); _proxyServer.Name = "Proxy" + _proxyServer.Name; _proxyServer.evClientSubmitSm += WhenReceiveSubmitSmFromClient; _proxyClient = new SmppClient(); _proxyClient.Name = "Proxy" + _proxyClient.Name; _proxyClient.evDeliverSm += WhenDeliveryReceiptReceivedFromSMSC; _storage.ReceiptReadyForDelivery += WhenReceiptIsReadyForDelivery; }
/// <summary> Constructor For ESMS mode </summary> /// <param name="connectionId"></param> /// <param name="shortLongCode"></param> /// <param name="connectionMode"></param> /// <param name="host"></param> /// <param name="port"></param> /// <param name="userName"></param> /// <param name="password"></param> /// <param name="logKey"></param> /// <param name="defaultEncoding"></param> /// <param name="connectionEventHandler"></param> /// <param name="receivedMessageHandler"></param> /// <param name="receivedGenericNackHandler"></param> /// <param name="submitMessageHandler"></param> /// <param name="queryMessageHandler"></param> /// <param name="logEventHandler"></param> /// <param name="pduDetailsEventHandler"></param> public ESMEConnection(int connectionId, string shortLongCode, ConnectionModes connectionMode, string host, int port, string userName, string password, string logKey, DataCodings defaultEncoding, CONNECTION_EVENT_HANDLER connectionEventHandler, RECEIVED_MESSAGE_HANDLER receivedMessageHandler, RECEIVED_GENERICNACK_HANDLER receivedGenericNackHandler, SUBMIT_MESSAGE_HANDLER submitMessageHandler, QUERY_MESSAGE_HANDLER queryMessageHandler, LOG_EVENT_HANDLER logEventHandler, PDU_DETAILS_EVENT_HANDLER pduDetailsEventHandler) { // Properties ConnectionId = connectionId; ShortLongCode = shortLongCode; ConnectionMode = connectionMode; Host = host; Port = port; UserName = userName; Password = password; LogKey = string.Format("{0}-{1}-{2}", logKey, ConnectionMode, ConnectionId); // Bind user events ConnectionEventHandler = connectionEventHandler; ReceivedMessageHandler = receivedMessageHandler; ReceivedGenericNackHandler = receivedGenericNackHandler; SubmitMessageHandler = submitMessageHandler; QueryMessageHandler = queryMessageHandler; LogEventHandler = logEventHandler; PduDetailsEventHandler = pduDetailsEventHandler; // Create the connection to the server Client = new SmppClient(defaultEncoding); // Bind Internal ESME required events Client.ConnectEvent += new SmppClient.ConnectedEventHandler(ClientEventConnect); Client.DeliverSmEvent += new SmppClient.DeliverSmEventHandler(ClientEventDeliverSm); Client.DisconnectEvent += new SmppClient.DisconnectEventHandler(ClientEventDisconnect); Client.EnquireLinkSmEvent += new SmppClient.EnquireLinkSmEventHandler(ClientEventEnquireLinkSm); Client.EnquireLinkSmRespEvent += new SmppClient.EnquireLinkSmRespEventHandler(ClientEventEnquireLinkSmResp); Client.ErrorEvent += new SmppClient.ErrorEventHandler(ClientEventError); Client.GenericNackSmEvent += new SmppClient.GenericNackSmEventHandler(ClientEventGenericNackSm); Client.QuerySmRespEvent += new SmppClient.QuerySmRespEventHandler(ClientEventQuerySmResp); Client.SubmitSmRespEvent += new SmppClient.SubmitSmRespEventHandler(ClientEventSubmitSmResp); Client.UnBindSmEvent += new SmppClient.UnBindSmEventHandler(ClientEventUnBindSm); Client.PduDetailsEvent += new SmppClient.PduDetailsEventHandler(ClientEventPduDetails); // Start a thread to get this connection ConnectionThread = new Thread(new ThreadStart(PerformConnectClient)); ConnectionThread.Start(); }
public SmppClientDemo() { //HOW TO INSTALL LICENSE FILE //==================== //After purchase you will receive Inetlab.SMPP.license file per E-Mail. //Add this file into the root of project where you have a reference on Inetlab.SMPP.dll. Change "Build Action" of the file to "Embedded Resource". //Set license before using Inetlab.SMPP classes in your code: // C# // Inetlab.SMPP.LicenseManager.SetLicense(this.GetType().Assembly.GetManifestResourceStream(this.GetType(), "Inetlab.SMPP.license" )); // // VB.NET // Inetlab.SMPP.LicenseManager.SetLicense(Me.GetType().Assembly.GetManifestResourceStream(Me.GetType(), "Inetlab.SMPP.license")) InitializeComponent(); LogManager.SetLoggerFactory(new TextBoxLogFactory(tbLog, LogLevel.Info)); _log = LogManager.GetLogger(GetType().Name); AppDomain.CurrentDomain.UnhandledException += (sender, args) => { LogManager.GetLogger("AppDomain").Fatal((Exception)args.ExceptionObject, "Unhandled Exception"); }; _client = new SmppClient(); _client.ResponseTimeout = TimeSpan.FromSeconds(60); _client.EnquireLinkInterval = TimeSpan.FromSeconds(20); _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.evServerCertificateValidation += OnCertificateValidation; _messageComposer = new MessageComposer(); _messageComposer.evFullMessageReceived += OnFullMessageReceived; _messageComposer.evFullMessageTimeout += OnFullMessageTimeout; }
public Program() { _messageStore = new DummyMessageStore(); _server.evClientBind += ServerOnClientBind; _server.evClientSubmitSm += ServerOnClientSubmitSm; _server.Start(); using (SmppClient client = new SmppClient()) { client.Connect("localhost", 7777); client.Bind("admin", "admin"); Console.WriteLine("Performance: Conected + "); } }
public static async Task Run() { // <Sample> using (SmppServer server = new SmppServer(new IPEndPoint(IPAddress.Any, 7777))) { server.EnabledSslProtocols = SslProtocols.Tls12; server.ServerCertificate = new X509Certificate2("server_certificate.p12", "cert_password"); server.Start(); server.evClientConnected += (sender, client) => { var clientCertificate = client.ClientCertificate; //You can validate client certificate and disconnect if it is not valid. }; using (SmppClient client = new SmppClient()) { client.EnabledSslProtocols = SslProtocols.Tls12; //if required you can be authenticated with client certificate client.ClientCertificates.Add(new X509Certificate2("client_certificate.p12", "cert_password")); if (await client.Connect("localhost", 7777)) { BindResp bindResp = await client.Bind("username", "password"); if (bindResp.Header.Status == CommandStatus.ESME_ROK) { var submitResp = await client.Submit( SMS.ForSubmit() .From("111") .To("436641234567") .Coding(DataCodings.UCS2) .Text("Hello World!")); if (submitResp.All(x => x.Header.Status == CommandStatus.ESME_ROK)) { client.Logger.Info("Message has been sent."); } } await client.Disconnect(); } } } //</Sample> }
public static async Task StartApp() { using (SmppServer server = new SmppServer(new IPEndPoint(IPAddress.Any, 7777))) { server.evClientBind += (sender, client, data) => { /*accept all*/ }; server.evClientSubmitSm += (sender, client, data) => { /*receive all*/ }; server.Start(); using (SmppClient client = new SmppClient()) { await client.Connect("localhost", 7777); await client.Bind("username", "password"); Console.WriteLine("Performance: " + await RunTest(client, 50000) + " m/s"); } } }
static async Task Main(string[] args) { appSw = Stopwatch.StartNew(); Console.WriteLine("#############################"); Console.WriteLine("SMPP Client demo"); Console.WriteLine("To exit, press CTRL+C"); Console.WriteLine("#############################"); Console.WriteLine("Initializing SMPP client.."); smppClient = new SmppClient(); InitializeEvents(); Console.WriteLine("--SMPP client initialized"); await ConnectAsync(); GetAuthInput(); await BindAsync(); }
public static async Task <int> RunTest(SmppClient client, int messagesNumber) { List <Task> tasks = new List <Task>(); Stopwatch watch = Stopwatch.StartNew(); for (int i = 0; i < messagesNumber; i++) { tasks.Add(client.Submit( SMS.ForSubmit() .From("111") .To("222") .Coding(DataCodings.UCS2) .Text("test"))); } await Task.WhenAll(tasks); watch.Stop(); return(Convert.ToInt32(messagesNumber / watch.Elapsed.TotalSeconds)); }
public static async Task SendSms(string phoneNumber, string smsText) { string filePath = ConfigurationManager.AppSettings.Get("SMPPLogPath"); LogManager.SetLoggerFactory(name => new FileLogger(filePath, LogLevel.All)); using (SmppClient client = new SmppClient()) { try { if (await client.Connect(new DnsEndPoint("smpp.server", 7777, AddressFamily.InterNetwork))) { BindResp bindResp = await client.Bind("username", "password"); if (bindResp.Header.Status == CommandStatus.ESME_ROK) { var submitResp = await client.Submit( SMS.ForSubmit() .From("short code") .To(phoneNumber) .Coding(DataCodings.UCS2) .Text(smsText)); if (submitResp.All(x => x.Header.Status == CommandStatus.ESME_ROK)) { client.Logger.Info("Message has been sent."); } } await client.Disconnect(); } } catch (Exception ex) { client.Logger.Error("Failed send message", ex); } } }
/// <summary> Dispose </summary> /// <param name="disposing"></param> protected void Dispose(bool disposing) { WriteLog("ESMEConnection : Dispose : Started"); if (!Disposed) { // Note disposing has begun Disposed = true; try { WriteLog("ESMEConnection : Dispose : Info : Wait For Connection Thread To Die"); // Kill the PerformConnectClient thread ConnectEvent.Set(); ConnectionThread.Join(5000); WriteLog("ESMEConnection : Dispose : Info : Disconnect from smpp Started"); Client.Dispose(); Client = null; WriteLog("ESMEConnection : Dispose : Info : Disconnect from smpp Completed"); } catch (Exception exception) { WriteLog(LogEventNotificationTypes.Email, "ESMEConnection : Dispose : ERROR : {0}", exception.ToString()); } // Kill the PerformConnectClient thread ConnectEvent.Set(); } WriteLog("ESMEConnection : Dispose : Completed"); }
/// <summary> Deserialize this saved data to the SubmitSm </summary> /// /// <param name="client"> The client. </param> /// <param name="data"> The serialized SubmitSm PDU. </param> /// /// <returns> A SubmitSm. </returns> /// public SubmitSm Deserialize(SmppClient client, byte[] data) { SmppReader reader = new SmppReader(client.EncodingMapper); return((SubmitSm)reader.ReadPDU(data)); }
private void SendMessageCompleteCallback(IAsyncResult result) { SmppClient client = (SmppClient)result.AsyncState; client.EndSendMessage(result); }
public SmppManager(string address, int port) { smppClient = new SmppClient(); smppClient.Start(); }
static void Main(string[] args) { Common.Logging.LogManager.Adapter = new Common.Logging.Simple.DebugLoggerFactoryAdapter(); var encSrv = new SmppEncodingService(); var hexBytes = "000000dd0000000500000000019182410001013334363439323836383039000501657669636572746961000400000000000000008569643a323533303932393134353232363637333732207375623a30303120646c7672643a303031207375626d697420646174653a3133303932393136353220646f6e6520646174653a3133303932393136353220737461743a44454c49565244206572723a3030303020746578743a1b3c657669534d531b3e0a534d532064652050727565042300030300000427000102001e001332353330393239313435323236363733373200"; var packet = StringToByteArray(hexBytes); var bodyBytes = packet.Skip(16).ToArray(); var pdu = PDU.CreatePDU(PDUHeader.Parse(new ByteBuffer(packet), encSrv), encSrv); pdu.SetBodyData(new ByteBuffer(bodyBytes)); var receiptedMessageId = pdu.GetOptionalParamString(JamaaTech.Smpp.Net.Lib.Protocol.Tlv.Tag.receipted_message_id); //Assert.AreEqual("253092914522667372", pdu.ReceiptedMessageId); _Log.Info("Start"); //Trace.Listeners.Add(new ConsoleTraceListener()); smppConfig = GetSmppConfiguration(); //SMPPEncodingUtil.UCS2Encoding = Encoding.UTF8; client = CreateSmppClient(smppConfig); client.Start(); // must wait until connected before start sending while (client.ConnectionState != SmppConnectionState.Connected) { Thread.Sleep(100); } // Accept command input bool bQuit = false; do { // Hit Enter in the terminal once the binds are up to see this prompt Console.WriteLine("Commands"); Console.WriteLine("send 123456 hello"); Console.WriteLine("quit"); Console.WriteLine(""); Console.Write("\n#>"); string command = Console.ReadLine(); if (command.Length == 0) { continue; } switch (command.Split(' ')[0].ToString()) { case "quit": case "exit": case "q": bQuit = true; break; default: ProcessCommand(command); break; } if (bQuit) { break; } } while (true); if (client != null) { client.Dispose(); } }
public SmppManager() { smppClient = new SmppClient(); smppClient.Start(); }