Beispiel #1
0
 private void Open(int timeOut)
 {
     try
     {
         if (Monitor.TryEnter(vConnSyncRoot))
         {
             //No thread is in a connecting or reconnecting state
             if (vState != SmppConnectionState.Closed)
             {
                 vLastException = new InvalidOperationException("You cannot open while the instance is already connected");
                 throw vLastException;
             }
             //
             SessionBindInfo bindInfo   = null;
             bool            useSepConn = false;
             lock (vProperties.SyncRoot)
             {
                 bindInfo   = vProperties.GetBindInfo();
                 useSepConn = vProperties.InterfaceVersion == InterfaceVersion.v33;
             }
             try { OpenSession(bindInfo, useSepConn, timeOut); }
             catch (Exception ex)
             {
                 _Log.ErrorFormat("OpenSession: {0}", ex, ex.Message);
                 if (vTraceSwitch.TraceError)
                 {
                     Trace.TraceError(ex.ToString());
                 }
                 vLastException = ex; throw;
             }
             vLastException = null;
         }
         else
         {
             //Another thread is already in either a connecting or reconnecting state
             //Wait until the thread finishes
             Monitor.Enter(vConnSyncRoot);
             //Now, the thread has finished connecting,
             //Check on the result if the thread encountered any problem during connection
             if (vLastException != null)
             {
                 throw vLastException;
             }
         }
     }
     finally
     {
         Monitor.Exit(vConnSyncRoot);
     }
 }
        internal SessionBindInfo GetBindInfo()
        {
            SessionBindInfo bindInfo = new SessionBindInfo();

            bindInfo.SystemID         = vSystemID;
            bindInfo.Password         = vPassword;
            bindInfo.ServerName       = vHost;
            bindInfo.Port             = vPort;
            bindInfo.InterfaceVersion = vInterfaceVersion;
            bindInfo.AddressTon       = vAddressTon;
            bindInfo.AddressNpi       = vAddressNpi;
            bindInfo.SystemType       = vSystemType;
            return(bindInfo);
        }
Beispiel #3
0
        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());
        }
Beispiel #4
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;
         }
     }
 }