// <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();
                }
            }
        }
        // <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();
                    }
                }
            }
        }
        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;
            }
        }
        public async Task Run(Uri smscUrl)
        {
            _proxyServer.Start();

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

            BindResp bindResp = await _proxyClient.Bind("proxy", "test");
        }
        private void ClientOnRecoverySucceeded(object sender, BindResp data)
        {
            _log.Info("Connection has been recovered.");

            Sync(this, () =>
            {
                bConnect.Enabled    = false;
                bDisconnect.Enabled = true;
                bSubmit.Enabled     = true;
                cbReconnect.Enabled = false;
            });
        }
Beispiel #6
0
        public void Add(BindResp bindResp)
        {
            var res = AnResponse.Bulder().BindResp(bindResp).ToAnResponse();

            if (res.IsSuccessful)
            {
                SuccessResponses.Add(res);
            }
            else
            {
                ErrorResponse = res;
            }
        }
Beispiel #7
0
        private void ConnectSocket()
        {
            int vConnectNum = 0;

            while (true)
            {
                IPAddress  vIp         = IPAddress.Parse(SocketConfig.SocketIp);
                IPEndPoint vIpEndPoint = new IPEndPoint(vIp, SocketConfig.Port);
                _Socket = new Socket(vIpEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
                try
                {
                    _Socket.Connect(vIpEndPoint);
                    if (_Socket.Connected)
                    {
                        break;
                    }
                    else
                    {
                        vConnectNum++;
                    }
                }
                catch
                {
                    try
                    {
                        Thread.Sleep(1000 * 1);
                    }
                    catch (System.Exception ex)
                    {
                        throw ex;
                    }
                    vConnectNum++;
                }
                if (vConnectNum >= 3)
                {
                    Exception.UnicomSgipException.CustomerException("连接失败!");
                }
            }
            _Socket.NoDelay = true;
            Bind vBindBll = new Bind();

            vBindBll.FillBodyBytes();
            vBindBll.Write(_Socket);

            BindResp vRes = (BindResp)vBindBll.Read(_Socket);

            if (vRes.Result != 0)
            {
                Exception.UnicomSgipException.CustomerException(Help.ResultCode.ContainsKey(vRes.Result) ? Help.ResultCode[vRes.Result] : "unknow error");
            }
        }
        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");
                }
            }
        }
Beispiel #9
0
 public IAnResponseBulder BindResp(BindResp bindResp)
 {
     try
     {
         response.statusCode = Converter.ToStatusCode(bindResp.Status);
         if (!response.IsSuccessful)
         {
             response.SubmitSmRespErrorData = JsonConvert.SerializeObject(bindResp);
         }
     }
     catch (Exception ex)
     {
     }
     return(this);
 }
        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>
        }
Beispiel #11
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);
        }
Beispiel #12
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);
                }
            }
        }