示例#1
0
文件: Form1.cs 项目: Marr0nie/TestSMS
        private void button1_Click(object sender, EventArgs e)
        {
            SMPPEncodingUtil.UCS2Encoding = Encoding.BigEndianUnicode;

            mmSessionBindInfo                  = new SessionBindInfo();
            mmSessionBindInfo.SystemID         = "********";
            mmSessionBindInfo.Password         = "******";
            mmSessionBindInfo.ServerName       = "*******";
            mmSessionBindInfo.Port             = 1234;
            mmSessionBindInfo.InterfaceVersion = InterfaceVersion.v34;
            mmSessionBindInfo.SystemType       = "SMPP";
            mmSessionBindInfo.AllowTransmit    = true;
            mmSessionBindInfo.AllowReceive     = true;
            mmSessionBindInfo.AddressNpi       = NumberingPlanIndicator.Unknown;
            mmSessionBindInfo.AddressTon       = TypeOfNumber.Unknown;
            mmSession              = SmppClientSession.Bind(mmSessionBindInfo, 0);
            mmSession.PduReceived += new EventHandler <PduReceivedEventArgs>(PduReceivedEventHander);


            mmSubmitSm = new SubmitSm();

            mmSubmitSm.DataCoding                 = DataCoding.UCS2;
            mmSubmitSm.ServiceType                = "CMT";      // cellular  messaging
            mmSubmitSm.RegisteredDelivery         = RegisteredDelivery.DeliveryReceipt;
            mmSubmitSm.DestinationAddress.Address = "********"; // destination
            mmSubmitSm.DestinationAddress.Npi     = NumberingPlanIndicator.ISDN;
            mmSubmitSm.DestinationAddress.Ton     = TypeOfNumber.International;
            mmSubmitSm.SourceAddress.Npi          = NumberingPlanIndicator.Unknown;
            mmSubmitSm.SourceAddress.Ton          = TypeOfNumber.Aphanumeric;
            mmSubmitSm.SourceAddress.Address      = "*********";

            try
            {
                mmSubmitSm.SetMessageText(Encoding.UTF8.GetString(Encoding.UTF8.GetBytes("Текст")), DataCoding.UCS2);
                mmSubmitSmResp = mmSession.SendPdu(mmSubmitSm) as SubmitSmResp;
                MessageBox.Show(DateTime.Now.ToString());
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }

            MessageBox.Show(mmSubmitSmResp.MessageID + " , " + mmSubmitSmResp.Header.ErrorCode.ToString() + " , " + mmSubmitSm.GetMessageText());
        }
示例#2
0
        private void CloseSession()
        {
            var oldState = _vState;

            if (_vState == SmppConnectionState.Closed)
            {
                return;
            }
            _vState = SmppConnectionState.Closed;

            RaiseConnectionStateChangeEvent(SmppConnectionState.Closed, oldState);
            if (_vTrans != null)
            {
                _vTrans.EndSession();
            }
            if (_vRecv != null)
            {
                _vRecv.EndSession();
            }
            _vTrans = null;
            _vRecv  = null;
        }
示例#3
0
        private void CloseSession()
        {
            SmppConnectionState oldState = SmppConnectionState.Closed;

            oldState = vState;
            if (vState == SmppConnectionState.Closed)
            {
                return;
            }
            vState = SmppConnectionState.Closed;

            RaiseConnectionStateChangeEvent(SmppConnectionState.Closed, oldState);
            if (vTrans != null)
            {
                vTrans.EndSession();
            }
            if (vRecv != null)
            {
                vRecv.EndSession();
            }
            vTrans = null;
            vRecv  = null;
        }
示例#4
0
 private void InitializeSession(SmppClientSession session)
 {
     session.EnquireLinkInterval = vKeepAliveInterval;
     session.PduReceived        += PduReceivedEventHander;
     session.SessionClosed      += SessionClosedEventHandler;
 }
示例#5
0
 private void OpenSession(SessionBindInfo bindInfo, bool useSeparateConnections, int timeOut)
 {
     ChangeState(SmppConnectionState.Connecting);
     if (useSeparateConnections)
     {
         //Create two separate sessions for sending and receiving
         try
         {
             bindInfo.AllowReceive  = true;
             bindInfo.AllowTransmit = false;
             vRecv = SmppClientSession.Bind(bindInfo, timeOut);
             InitializeSession(vRecv);
         }
         catch
         {
             ChangeState(SmppConnectionState.Closed);
             //Start reconnect timer
             StartTimer();
             throw;
         }
         //--
         try
         {
             bindInfo.AllowReceive  = false;
             bindInfo.AllowTransmit = true;
             vTrans = SmppClientSession.Bind(bindInfo, timeOut);
             InitializeSession(vTrans);
         }
         catch
         {
             try { vRecv.EndSession(); }
             catch { /*Silent catch*/ }
             vRecv = null;
             ChangeState(SmppConnectionState.Closed);
             //Start reconnect timer
             StartTimer();
             throw;
         }
         ChangeState(SmppConnectionState.Connected);
     }
     else
     {
         //Use a single session for both sending and receiving
         bindInfo.AllowTransmit = true;
         bindInfo.AllowReceive  = true;
         try
         {
             SmppClientSession session = SmppClientSession.Bind(bindInfo, timeOut);
             vTrans = session;
             vRecv  = session;
             InitializeSession(session);
             ChangeState(SmppConnectionState.Connected);
         }
         catch (SmppException ex)
         {
             if (ex.ErrorCode == SmppErrorCode.ESME_RINVCMDID)
             {
                 //If SMSC returns ESME_RINVCMDID (Invalid command id)
                 //the SMSC might not be supporting the BindTransceiver PDU
                 //Therefore, we can try to use bind with separate connections
                 OpenSession(bindInfo, true, timeOut);
             }
             else
             {
                 ChangeState(SmppConnectionState.Closed);
                 //Start background timer
                 StartTimer();
                 throw;
             }
         }
         catch
         {
             ChangeState(SmppConnectionState.Closed);
             StartTimer();
             throw;
         }
     }
 }