Exemple #1
0
        private static TcpIpSession CreateTcpIpSession(SessionBindInfo bindInfo)
        {
            //Check that Host is not an empty string or null
            if (string.IsNullOrEmpty(bindInfo.ServerName))
            {
                throw new InvalidOperationException("Host cannot be an empty string or null");
            }
            //Check the port number is not set to an invalid value
            if (bindInfo.Port < IPEndPoint.MinPort || bindInfo.Port > IPEndPoint.MaxPort)
            {
                throw new InvalidOperationException(
                          string.Format("Port must be set to a valid value between '{0}' and '{1}'",
                                        IPEndPoint.MinPort, IPEndPoint.MaxPort));
            }
            IPAddress    address = null;
            TcpIpSession session = null;

            if (!IPAddress.TryParse(bindInfo.ServerName, out address))
            {
                session = TcpIpSession.OpenClientSession(bindInfo.ServerName, bindInfo.Port);
            }
            else
            {
                session = TcpIpSession.OpenClientSession(address, bindInfo.Port);
            }
            return(session);
        }
Exemple #2
0
 public PDUTransmitter(TcpIpSession session)
 {
     if (session == null)
     {
         throw new ArgumentNullException("session");
     }
     vTcpIpSession = session;
 }
Exemple #3
0
 private void DestroyTcpIpSession()
 {
     if (_vTcpIpSession == null)
     {
         return;
     }
     _vTcpIpSession.SessionClosed -= TcpIpSessionClosedEventHandler;
     _vTcpIpSession.EndSession();
     _vTcpIpSession = null;
 }
 /// <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)
 {
     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;
     //--Create and initialize a trace switch
     vTraceSwitch = new TraceSwitch("StreamParserSwitch", "Stream perser switch");
 }
Exemple #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;
     }
 }