private async Task Bind() { _log.Info("Bind client with SystemId: {0}", tbSystemId.Text); ConnectionMode mode = ConnectionMode.Transceiver; bDisconnect.Enabled = true; mode = (ConnectionMode)cbBindingMode.SelectedItem; BindResp resp = await _client.Bind(tbSystemId.Text, tbPassword.Text, mode); switch (resp.Header.Status) { case CommandStatus.ESME_ROK: _log.Info("Bind succeeded: Status: {0}, SystemId: {1}", resp.Header.Status, resp.SystemId); bSubmit.Enabled = true; break; default: _log.Warn("Bind failed: Status: {0}", resp.Header.Status); await Disconnect(); break; } }
// <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 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(); } } }
public async Task Run(Uri smscUrl) { _proxyServer.Start(); await _proxyClient.Connect(smscUrl.Host, smscUrl.Port); BindResp bindResp = await _proxyClient.Bind("proxy", "test"); }
public Task SendCommmand2() { string shortCode = "7777"; // _client.EsmeAddress = new SmeAddress(shortCode, AddressTON.NetworkSpecific, AddressNPI.Private); _client.Bind("username", "password", ConnectionMode.Transceiver); return(_client.Submit(SMS.ForSubmit() .From(shortCode, AddressTON.NetworkSpecific, AddressNPI.Private) .To("+79171234567") .Text("USSD text") .Coding(DataCodings.Class1MEMessage8bit) .AddParameter(new UssdServiceOpParameter(USSDOperation.USSRRequest)) //USSR request .AddParameter(OptionalTags.ItsSessionInfo, new byte[] { 11 }) )); }
public static bool ConnectSMPP(IList <SmppModel> listSMPP) { try { if (smppClient == null) { Initialize(); } if (smppClient.Status == ConnectionStatus.Closed) { foreach (var smpp in listSMPP) { logger.Info(AppConst.A("ConnectSMPP", "Start connect!", smpp.HOST_NAME, smpp.PORT, smpp.SYSTEM_ID, smpp.PASSWORD)); if (!String.IsNullOrEmpty(smpp.HOST_NAME) && !String.IsNullOrEmpty(smpp.SYSTEM_ID)) { smppClient.AddrTon = smpp.ADDR_TON; smppClient.AddrNpi = smpp.ADDR_NPI; smppClient.SystemType = String.Empty; smppClient.EnabledSslProtocols = SslProtocols.None; if (smppClient.Connect(smpp.HOST_NAME, smpp.PORT)) { var bindResp = smppClient.Bind(smpp.SYSTEM_ID, smpp.PASSWORD, ConnectionMode.Transmitter); if (bindResp.Status == CommandStatus.ESME_ROK) { logger.Info(AppConst.A("ConnectSMPP", "Connected!", bindResp.Status)); return(true); } else { logger.Error(AppConst.A("ConnectSMPP", "Username or password invalid!", bindResp.Status)); } } else { logger.Error(AppConst.A("ConnectSMPP", "Connect fail!")); } } } } else { return(true); } } catch (Exception ex) { logger.Error(AppConst.A("ConnectSMPP", listSMPP.Count, ex)); } return(false); }
public async Task Connect() { if (await _client.Connect("smpp.server.com", 7777)) { _log.Info("Connected to SMPP server"); BindResp bindResp = await _client.Bind("username", "password", ConnectionMode.Transceiver); if (bindResp.Header.Status == CommandStatus.ESME_ROK) { _log.Info("Bound with SMPP server"); } } }
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 IAnMultiResponse SendMessages(AnMultiMessage multiMessage) { if (anBind == null) { throw new Exception("No Connection."); } var multiResponse = new AnMultiResponse(); client.Connect(hostName, port); if (client.Status == ConnectionStatus.Open) { var pdu = anBind.NewBind(); BindResp bindResponce = client.Bind(pdu.SystemId, pdu.Password, ConnectionMode.Transceiver); if (client.Status == ConnectionStatus.Bound) { var builder = ForSubmit(multiMessage); IList <SubmitSmResp> clientResponses = client.Submit(builder); multiResponse.Add(multiMessage, clientResponses); foreach (string phone in multiMessage.GetAdministrators()) { builder.To(phone); clientResponses = client.Submit(builder); multiResponse.Add(multiMessage, clientResponses); } foreach (AnMessage message in multiMessage) { clientResponses = client.Submit(ForSubmit(message)); multiResponse.Add(message, clientResponses); } return(multiResponse); } multiResponse.Add(bindResponce); } else { multiResponse.Add(StatusCode.SmppClient_NoConnection); } return(multiResponse); }
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"); } } }
private static async Task BindAsync() { Console.WriteLine($"Authenticating ({systemId}:{password})"); var resp = await smppClient.Bind(systemId, password); if (resp.Header.Status == CommandStatus.ESME_ROK) { Console.WriteLine($"--Account authenticated. Welcome '{systemId}'!"); await SendAsync(); } else { Console.WriteLine($"--Authentication failed. BindResp: { resp.Header.Status }"); Console.WriteLine($"--Press any key to re-enter your credential, or CTRL+C to exit"); Console.ReadKey(true); GetAuthInput(); await ConnectAsync(); await BindAsync(); } }
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> Called to authenticate the system </summary> private bool Bind() { WriteLog("ESMEConnection : Bind : Started : Host[{0}] Port[{1}]", Host, Port); bool retVal = false; try { // Authenticate to the SMPP Server BindSmResp btrp = Client.Bind(UserName, Password, ConnectionMode); // How did we do switch (btrp.Status) { case CommandStatus.ESME_ROK: IsBound = true; ConnectionEventHandler(LogKey, ConnectionEventTypes.Bound, string.Format("ESMEConnection : Bind : Info : Host[{0}] Port[{1}] Bind Established", Host, Port)); retVal = true; break; default: ConnectionEventHandler(LogKey, ConnectionEventTypes.BindingAttemptFailed, string.Format("ESMEConnection : Bind : ERROR : Host[{0}] Port[{1}] Status[{2}]", Host, Port, btrp.Status.ToString())); break; } } catch (Exception exception) { WriteLog("ESMEConnection : Bind : ERROR : Host[{0}] Port[{1}] Bind Failed {2}", Host, Port, exception.Message); } WriteLog("ESMEConnection : Bind : Completed : Host[{0}] Port[{1}] RetVal[{2}]", Host, Port, retVal); return(retVal); }