Exemplo n.º 1
0
 private SmppClientSession(SmppEncodingService smppEncodingService)
 {
     vSmppEncodingService = smppEncodingService;
     InitializeTimer();
     vSyncRoot = new object();
     vDefaultResponseTimeout = 5000;
     vSmscId   = "";
     vSystemId = "";
     vPassword = "";
     vCallback = new SendPduCallback(SendPdu);
     //-- Create and initialize trace switch
 }
Exemplo n.º 2
0
        internal BindRequest CreatePdu(SmppEncodingService smppEncodingService)
        {
            BindRequest req = CreateBindBdu(smppEncodingService);

            req.AddressNpi       = vAddressNpi;
            req.AddressTon       = vAddressTon;
            req.SystemID         = vSystemID;
            req.Password         = vPassword;
            req.SystemType       = vSystemType;
            req.InterfaceVersion = vInterfaceVersion == InterfaceVersion.v33 ? (byte)0x33 : (byte)0x34;
            return(req);
        }
Exemplo n.º 3
0
        public static Udh Parse(ByteBuffer buffer, SmppEncodingService smppEncodingService)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }
            //There must be at least 3 bytes for UDHL, IEI, IEDL
            if (buffer.Length < 3)
            {
                throw new SmppException(SmppErrorCode.ESME_RUNKNOWNERR, "Invalid UDH field");
            }
            int length = buffer.Remove(); //UDH Length
            int iei    = buffer.Remove(); //Information element identifier
            int ieidl  = buffer.Remove(); //Information element identifier data length

            /*
             * This udh implementation supports only concatenated messages with
             * 8 bits (IEI = 0) and 16 bits (IEI = 8) reference number.
             * Therefore, the expected number of bytes indicated by the UDHL field
             * should be either 5 or 6 octects, otherwise the udh is unsupported.
             */
            int segId = 0;
            int count = 0;
            int seq   = 0;

            //--
            //Confirm that we have enough bytes as indicated by the UDHL
            if (buffer.Length < ieidl)
            {
                throw new SmppException(SmppErrorCode.ESME_RUNKNOWNERR, "Invalid UDH field");
            }
            if (length == 5 && iei == 0 && ieidl == 3) //8 bits message reference
            {
                segId = buffer.Remove();
                count = buffer.Remove();
                seq   = buffer.Remove();
            }
            else if (length == 6 && iei == 8 && ieidl == 4) //16 bits message reference
            {
                segId = smppEncodingService.GetShortFromBytes(buffer.Remove(2));
                count = buffer.Remove();
                seq   = buffer.Remove();
            }
            else
            {
                throw new SmppException(SmppErrorCode.ESME_RUNKNOWNERR, "Invalid or unsupported UDH field");
            }
            Udh udh = new Udh(segId, count, seq);

            return(udh);
        }
Exemplo n.º 4
0
 private BindRequest CreateBindBdu(SmppEncodingService smppEncodingService)
 {
     if (vAllowReceive && vAllowTransmit)
     {
         return(new BindTransceiver(smppEncodingService));
     }
     else if (vAllowTransmit)
     {
         return(new BindTransmitter(smppEncodingService));
     }
     else if (vAllowReceive)
     {
         return(new BindReceiver(smppEncodingService));
     }
     else
     {
         throw new InvalidOperationException("Both AllowTransmit and AllowReceive cannot be set to false");
     }
 }
Exemplo n.º 5
0
 public static SmppClientSession Bind(SessionBindInfo bindInfo, int timeOut, SmppEncodingService smppEncodingService)
 {
     try
     {
         TcpIpSession tcpIpSession = null;
         if (bindInfo == null)
         {
             throw new ArgumentNullException("bindInfo");
         }
         //--
         tcpIpSession = CreateTcpIpSession(bindInfo);
         //--
         SmppClientSession smppSession = new SmppClientSession(smppEncodingService);
         smppSession.vTcpIpSession = tcpIpSession;
         smppSession.ChangeState(SmppSessionState.Open);
         smppSession.AssembleComponents();
         try { smppSession.BindSession(bindInfo, timeOut); }
         catch (Exception)
         {
             smppSession.DestroyTcpIpSession();
             smppSession.DisassembleComponents();
             throw;
         }
         return(smppSession);
     }
     catch (Exception ex)
     {
         _Log.ErrorFormat("200017:SMPP bind operation failed: {0}", ex, ex.Message);
         if (vTraceSwitch.TraceInfo)
         {
             string traceMessage = "200017:SMPP bind operation failed:";
             if (ex is SmppException)
             {
                 traceMessage += (ex as SmppException).ErrorCode.ToString() + " - ";
             }
             traceMessage += ex.Message;
             Trace.WriteLine(traceMessage);
         }
         throw;
     }
 }
Exemplo n.º 6
0
 /// <summary>
 /// Creates a new instance of the <see cref="StreamParser"/> class
 /// </summary>
 /// <param name="session">A <see cref="TcpIpSession"/></param>
 /// <param name="responseQueue">A <see cref="ResponseQueue"/> instance to which <see cref="ResponsePDU"/> pdu's are forwarded</param>
 /// <param name="requestProcessor">A callback delegate for processing <see cref="RequestPDU"/> pdu's</param>
 public StreamParser(TcpIpSession session, ResponseHandler responseQueue, PduProcessorCallback requestProcessor, SmppEncodingService smppEncodingService)
 {
     if (session == null)
     {
         throw new ArgumentNullException("session");
     }
     if (requestProcessor == null)
     {
         throw new ArgumentNullException("requestProcessor");
     }
     if (responseQueue == null)
     {
         throw new ArgumentNullException("responseQueue");
     }
     vTcpIpSession        = session;
     vProcessorCallback   = requestProcessor;
     vResponseHandler     = responseQueue;
     vSmppEncodingService = smppEncodingService;
     //--Create and initialize a trace switch
     vTraceSwitch = new TraceSwitch("StreamParserSwitch", "Stream perser switch");
 }