JamaaSMPP第三次连接时绑定操作失败

时间:2018-08-01 10:13:40

标签: c# windows-services smpp

我正在使用JamaaSMPP客户端发送和接收SMS。我在Windows服务中使用它,但面临一个奇怪的问题。当smppclient启动时,它将连接并再次连接,但是在尝试第三次连接时,绑定操作将失败并引发异常。这是我的日志:

  • 01/08/2018 02:49:07:服务已启动
  • 01/08/2018 02:50:07:正在连接
  • 01/08/2018 02:50:07:已连接
  • 01/08/2018 02:51:07:正在连接
  • 01/08/2018 02:51:07:已连接
  • 01/08/2018 02:52:07:正在连接
  • 01/08/2018 02:52:07:关闭
  • 01/08/2018 02:52:12:
  

client_ConnectionStateChanged:JamaaTech.Smpp.Net.Lib.SmppBindException:   绑定操作失败于   JamaaTech.Smpp.Net.Lib.SmppClientSession.BindSession(SessionBindInfo   bindInfo,Int32 timeOut)在   D:\ Work \ My \ JamaaSMPP \ JamaaTech.SMPP.Net.Lib \ SmppClientSession.cs:line   351在   JamaaTech.Smpp.Net.Lib.SmppClientSession.Bind(SessionBindInfo   在其中的bindInfo,Int32超时,SmppEncodingService smppEncodingService)   D:\ Work \ My \ JamaaSMPP \ JamaaTech.SMPP.Net.Lib \ SmppClientSession.cs:line   257点   JamaaTech.Smpp.Net.Client.SmppClient.OpenSession(SessionBindInfo   bindInfo,布尔型useSeparateConnections,Int32超时)   D:\ Work \ My \ JamaaSMPP \ JamaaTech.Smpp.Net.Client \ SmppClient.cs:第443行   在JamaaTech.Smpp.Net.Client.SmppClient.Open(Int32 timeOut)中   D:\ Work \ My \ JamaaSMPP \ JamaaTech.Smpp.Net.Client \ SmppClient.cs:第356行   在   JamaaTech.Smpp.Net.Client.SmppClient.AutoReconnectTimerEventHandler(Object   状态)   D:\ Work \ My \ JamaaSMPP \ JamaaTech.Smpp.Net.Client \ SmppClient.cs:第619行

这是我的代码

    static SmppClient CreateSmppClient()
            {

                SmppClient _client = new SmppClient();
                SmppConnectionProperties properties = _client.Properties;
                properties.SystemID = "XXXXXXX";
                properties.Password = "XXXXXXX";
                properties.Host = "10.10.10.10";
                properties.Port = Convert.ToInt32(0000);
                properties.SystemType = "transceiver";
                properties.DefaultServiceType = "transceiver";
                properties.AddressTon = TypeOfNumber.National;
                properties.AddressNpi = NumberingPlanIndicator.ISDN;
                properties.DefaultEncoding = DataCoding.ASCII; 

                _client.AutoReconnectDelay = Convert.ToInt32(5000);
                _client.KeepAliveInterval = Convert.ToInt32(15000);
                _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);
                return _client;

            }


var _client = CreateSmppClient();
                _client.Start();
                while (_client.ConnectionState != SmppConnectionState.Connected)
                    Thread.Sleep(500);



                    TextMessage _msg = new TextMessage();
                    _msg.SourceAddress = "000";
                    _msg.DestinationAddress = "93XXXXXXX";
                    _msg.Text = "sms";
                    _msg.RegisterDeliveryNotification = true;
                    try
                    {
                        _client.BeginSendMessage(_msg, SendMessageCompleteCallback, _client);
                    }
                    catch (SmppException ex)
                    {
                        Library.WriteErrorLog(ex.ErrorCode + " " + ex.Message);
                    }
                }

这是连接状态更改事件

private static void client_ConnectionStateChanged(object sender, ConnectionStateChangedEventArgs e)
        {
            var client = (SmppClient)sender;
            if (client.LastException != null)
                Library.WriteErrorLog("client_ConnectionStateChanged:" + client.LastException.ToString());
            switch (e.CurrentState)
            {
                case SmppConnectionState.Closed:
                    Library.WriteErrorLog("CLOSED");
                    e.ReconnectInteval = 5000;
                    break;
                case SmppConnectionState.Connected:
                    Library.WriteErrorLog("CONNECTED");
                    break;
                case SmppConnectionState.Connecting:
                    Library.WriteErrorLog("CONNECTING");
                    break;
            }
        }

0 个答案:

没有答案