Ejemplo n.º 1
0
        // <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();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        // <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();
                }
            }
        }
Ejemplo n.º 3
0
        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());
        }
        public async Task Run(Uri smscUrl)
        {
            _proxyServer.Start();

            await _proxyClient.Connect(smscUrl.Host, smscUrl.Port);

            BindResp bindResp = await _proxyClient.Bind("proxy", "test");
        }
Ejemplo n.º 5
0
        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");
                }
            }
        }
Ejemplo n.º 7
0
        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>
        }
Ejemplo n.º 9
0
        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);
        }
        private async Task Connect()
        {
            if (_client.Status == ConnectionStatus.Closed)
            {
                _log.Info("Connecting to " + tbHostname.Text);

                bConnect.Enabled    = false;
                bDisconnect.Enabled = false;
                cbReconnect.Enabled = false;


                _client.EsmeAddress = new SmeAddress("", (AddressTON)Convert.ToByte(tbAddrTon.Text), (AddressNPI)Convert.ToByte(tbAddrNpi.Text));
                _client.SystemType  = tbSystemType.Text;

                _client.ConnectionRecovery      = cbReconnect.Checked;
                _client.ConnectionRecoveryDelay = TimeSpan.FromSeconds(3);


                if (cbSSL.Checked)
                {
                    _client.EnabledSslProtocols = SslProtocols.Default;
                    _client.ClientCertificates.Clear();
                    _client.ClientCertificates.Add(new X509Certificate2("client.p12", "12345"));
                }
                else
                {
                    _client.EnabledSslProtocols = SslProtocols.None;
                }

                bool bSuccess = await _client.Connect(tbHostname.Text, Convert.ToInt32(tbPort.Text));

                if (bSuccess)
                {
                    _log.Info("SmppClient connected");

                    await Bind();
                }
                else
                {
                    bConnect.Enabled    = true;
                    cbReconnect.Enabled = true;
                    bDisconnect.Enabled = false;
                }
            }
        }
        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");
                }
            }
        }
Ejemplo n.º 12
0
        private static async Task ConnectAsync()
        {
            Stopwatch sw = Stopwatch.StartNew();

            Console.WriteLine("Connecting to MiniGateway SMPP server..");
            var connected = await smppClient.Connect(serverIp, port);

            if (!connected)
            {
                Console.WriteLine("--Fail to connect, press any key to try again. Press CTRL+C to exit");
                Console.ReadKey(true);
                await ConnectAsync();
            }
            else
            {
                Console.WriteLine($"--SMPP server connected [{sw.Elapsed}]");
            }
        }
Ejemplo n.º 13
0
        /// <summary> Called to connect to the SMPP server </summary>
        private bool Connect()
        {
            WriteLog("ESMEConnection : Connect : Started : Host[{0}] Port[{1}]", Host, Port);

            bool retVal = false;

            try
            {
                if (Client.Status == ConnectionStatus.Closed)
                {
                    Client.AddrNpi    = (byte)Npi.Unknown;
                    Client.AddrTon    = (byte)Ton.NetworkSpecific;
                    Client.SystemType = string.Empty;

                    retVal = Client.Connect(Host, Port);

                    if (Client.Status != ConnectionStatus.Closed)
                    {
                        ConnectionEventHandler(LogKey, ConnectionEventTypes.Connected, string.Format("ESMEConnection : Connect : Info : Host[{0}] Port[{1}] Connection Established", Host, Port));
                        retVal = true;
                    }
                    else
                    {
                        ConnectionEventHandler(LogKey, ConnectionEventTypes.ConnectionAttemptFailed, string.Format("ESMEConnection : Connect : WARNING : Host[{0}] Port[{1}] Connection Failure", Host, Port));
                    }
                }
                else
                {
                    WriteLog("ESMEConnection : Connect : Info : Host[{0}] Port[{1}] Connection Already Established", Host, Port);
                    retVal = true;
                }
            }

            catch (Exception exception)
            {
                WriteLog("ESMEConnection : Connect : ERROR : Host[{0}] Port[{1}] Connection Failed {2}", Host, Port, exception.Message);
            }

            WriteLog("ESMEConnection : Connect : Completed : Host[{0}] Port[{1}] RetVal[{2}]", Host, Port, retVal);

            return(retVal);
        }
Ejemplo n.º 14
0
        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);
                }
            }
        }