Exemple #1
0
        LdtpdService()
        {
            if (!String.IsNullOrEmpty(ldtpDebugEnv))
            {
                debug = true;
            }
            if (String.IsNullOrEmpty(ldtpPort))
            {
                ldtpPort = "4118";
            }
            common     = new Common(debug);
            windowList = new WindowList(common);

            try
            {
                listener = new HttpListener();
                listener.Prefixes.Add("http://localhost:" + ldtpPort + "/");
                listener.Prefixes.Add("http://+:" + ldtpPort + "/");
                // Listen on all possible IP address
                if (listenAllInterface != null && listenAllInterface.Length > 0)
                {
                    if (debug)
                    {
                        Console.WriteLine("Listening on all interface");
                    }
                    listener.Prefixes.Add("http://*:" + ldtpPort + "/");
                }
                else
                {
                    // For Windows 8, still you need to add firewall rules
                    // Refer: README.txt
                    if (debug)
                    {
                        Console.WriteLine("Listening only on local interface");
                    }
                }
                listener.Start();
            }
            catch (HttpListenerException ex)
            {
                common.LogMessage(ex);
                System.Environment.Exit(1);
            }
            svc = new Core(windowList, common, debug);
        }
Exemple #2
0
        static void SingleThreadExec()
        {
            bool   debug              = false;
            string ldtpDebugEnv       = Environment.GetEnvironmentVariable("LDTP_DEBUG");
            string ldtpPort           = Environment.GetEnvironmentVariable("LDTP_SERVER_PORT");
            string listenAllInterface = Environment.GetEnvironmentVariable(
                "LDTP_LISTEN_ALL_INTERFACE");

            if (!String.IsNullOrEmpty(ldtpDebugEnv))
            {
                debug = true;
            }
            if (String.IsNullOrEmpty(ldtpPort))
            {
                ldtpPort = "4118";
            }
            Common common = new Common(debug);

            /*
             * // If planning to use Remoting instead of HTTP
             * // use this commented portion of code
             * // NOTE: To have this at work, you need to add your
             * // app under Firewall
             * IDictionary props = new Hashtable();
             * props["name"] = "LdtpdService";
             * props["port"] = 4118;
             * HttpChannel channel = new HttpChannel(
             * props,
             * null,
             * new XmlRpcServerFormatterSinkProvider()
             * );
             * ChannelServices.RegisterChannel(channel, false);
             *
             * RemotingConfiguration.RegisterWellKnownServiceType(
             * typeof(LdtpdMain),
             * "service.rem",
             * WellKnownObjectMode.Singleton);
             * Console.WriteLine("Press <ENTER> to shutdown");
             * Console.ReadLine();
             * /**/
            WindowList   windowList = new WindowList(common);
            HttpListener listener   = new HttpListener();

            listener.Prefixes.Add("http://localhost:" + ldtpPort + "/");
            listener.Prefixes.Add("http://+:" + ldtpPort + "/");
            // Listen on all possible IP address
            if (String.IsNullOrEmpty(listenAllInterface))
            {
                if (debug)
                {
                    Console.WriteLine("Listening on all interface");
                }
                listener.Prefixes.Add("http://*:" + ldtpPort + "/");
            }
            else
            {
                // For Windows 8, still you need to add firewall rules
                // Refer: README.txt
                if (debug)
                {
                    Console.WriteLine("Listening only on local interface");
                }
            }
            listener.Start();
            XmlRpcListenerService svc = new Core(windowList, common, debug);

            try
            {
                while (true)
                {
                    GC.Collect();
                    try
                    {
                        if (debug)
                        {
                            Console.WriteLine("Waiting for clients");
                        }
                        HttpListenerContext context = listener.GetContext();
                        // Don't create LDTP instance here, this creates
                        // new object for every request !
                        // Moved before creating HttpListenerContext
                        //XmlRpcListenerService svc = new LdtpdMain();
                        if (debug)
                        {
                            Console.WriteLine("Processing request");
                        }
                        svc.ProcessRequest(context);

                        /*
                         * // FIXME: If trying to do parallel process
                         * // memory usage goes high and never comes back
                         * // This is required for startprocessmonitor API
                         * Thread parallelProcess = new Thread(delegate()
                         * {
                         *  try
                         *  {
                         *      svc.ProcessRequest(context);
                         *  }
                         *  finally
                         *  {
                         *      context.Response.Close();
                         *      context = null;
                         *      GC.Collect();
                         *  }
                         * });
                         * parallelProcess.Start();
                         * /* */
                        context.Response.Close();
                        context = null;
                    }
                    catch (InvalidOperationException ex)
                    {
                        common.LogMessage(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                common.LogMessage(ex);
            }
            finally
            {
                svc        = null;
                windowList = null;
                listener.Stop();
            }
        }
Exemple #3
0
 public Listener(XmlRpcListenerService svc, string uri)
 {
     _svc = svc;
     _lstner.Prefixes.Add(uri);
 }
Exemple #4
0
 public Listener(XmlRpcListenerService svc)
 {
     _svc = svc;
     _lstner.Prefixes.Add("http://127.0.0.1:11000/");
 }