예제 #1
0
        public void ListenerThreadFunc(object data)
        {
            WebListener webListener = data as WebListener;

            if (webListener == null)
            {
                return;
            }

            _RunCount++;
            while (!_bQuit)
            {
                try
                {
                    //Accept a new connection
                    Socket mySocket = webListener.Listener.AcceptSocket();
                    if (mySocket.Connected)
                    {
                        if (AsyncRequests)
                        {
                            ThreadPool.QueueUserWorkItem(new WaitCallback(HandleRequest), mySocket);
                        }
                        else
                        {
                            HandleRequest(mySocket);
                        }
                    }
                }
                catch
                {
                    if (Earth3d.Logging)
                    {
                        Earth3d.WriteLogMessage("Web Server Listener Exception");
                    }
                }
            }
            _RunCount--;
        }
        public bool Startup()
        {
            if (Earth3d.Logging) { Earth3d.WriteLogMessage("Starting Web Server"); }
            SetAccessLists();

            if (!initializedOnce)
            {
                RequestHandler.RegisterHandler(new HTTPImagesetWtml());
                RequestHandler.RegisterHandler(new HTTPLayerApi());
                RequestHandler.RegisterHandler(new HttpXmlRpc());
                RequestHandler.RegisterHandler(new HttpImageFiles());
                RequestHandler.RegisterHandler(new HttpCrossDomain());
                RequestHandler.RegisterHandler(new HttpClientStatus());
                XmlRpcMethod.RegisterDispatchMap(new SampClientReceiveNotification());
                initializedOnce = true;
            }

            try
            {
                 // Find IPV4 Address
                _bQuit = false;
                IpAddress = "";
                listeners.Clear();
                WebListener listener = null;
                foreach (IPAddress ipAdd in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
                {
                    if (ipAdd.AddressFamily == AddressFamily.InterNetwork)
                    {
                        if (string.IsNullOrEmpty(IpAddress) )
                        {
                            IpAddress = ipAdd.ToString();
                        }
                        if (ipAdd.ToString() != "127.0.0.1")
                        {
                            if (Earth3d.Logging)
                            {
                                Earth3d.WriteLogMessage(" Web Server - Adding:" + ipAdd.ToString());
                            }
                            listener = new WebListener(new ParameterizedThreadStart(ListenerThreadFunc), ipAdd);
                            listeners.Add(listener);
                            listener.Start();
                        }
                    }
                }
                if (Earth3d.Logging)
                {
                    Earth3d.WriteLogMessage(" Web Server - Adding Loopback");
                }
                // Add Loopback localhost
                listener = new WebListener(new ParameterizedThreadStart(ListenerThreadFunc), IPAddress.Loopback);
                listeners.Add(listener);
                listener.Start();

            }
            catch (Exception e)
            {
                if (Earth3d.Logging)
                {
                    Earth3d.WriteLogMessage("Failed Starting Web Server");
                    Earth3d.WriteLogMessage(e.Message);
                    Earth3d.WriteLogMessage(e.Source);
                    Earth3d.WriteLogMessage(e.StackTrace);

                }
                _bQuit = true;
                return false;
            }
            return true;
        }
예제 #3
0
        public bool Startup()
        {
            if (Earth3d.Logging)
            {
                Earth3d.WriteLogMessage("Starting Web Server");
            }
            SetAccessLists();

            if (!initializedOnce)
            {
                RequestHandler.RegisterHandler(new HTTPImagesetWtml());
                RequestHandler.RegisterHandler(new HTTPLayerApi());
                RequestHandler.RegisterHandler(new HttpXmlRpc());
                RequestHandler.RegisterHandler(new HttpImageFiles());
                RequestHandler.RegisterHandler(new HttpCrossDomain());
                RequestHandler.RegisterHandler(new HttpClientStatus());
                XmlRpcMethod.RegisterDispatchMap(new SampClientReceiveNotification());
                initializedOnce = true;
            }


            try
            {
                // Find IPV4 Address
                _bQuit    = false;
                IpAddress = "";
                listeners.Clear();
                WebListener listener = null;
                foreach (IPAddress ipAdd in Dns.GetHostEntry(Dns.GetHostName()).AddressList)
                {
                    if (ipAdd.AddressFamily == AddressFamily.InterNetwork)
                    {
                        if (string.IsNullOrEmpty(IpAddress))
                        {
                            IpAddress = ipAdd.ToString();
                        }
                        if (ipAdd.ToString() != "127.0.0.1")
                        {
                            if (Earth3d.Logging)
                            {
                                Earth3d.WriteLogMessage(" Web Server - Adding:" + ipAdd.ToString());
                            }
                            listener = new WebListener(new ParameterizedThreadStart(ListenerThreadFunc), ipAdd);
                            listeners.Add(listener);
                            listener.Start();
                        }
                    }
                }
                if (Earth3d.Logging)
                {
                    Earth3d.WriteLogMessage(" Web Server - Adding Loopback");
                }
                // Add Loopback localhost
                listener = new WebListener(new ParameterizedThreadStart(ListenerThreadFunc), IPAddress.Loopback);
                listeners.Add(listener);
                listener.Start();
            }
            catch (Exception e)
            {
                if (Earth3d.Logging)
                {
                    Earth3d.WriteLogMessage("Failed Starting Web Server");
                    Earth3d.WriteLogMessage(e.Message);
                    Earth3d.WriteLogMessage(e.Source);
                    Earth3d.WriteLogMessage(e.StackTrace);
                }
                _bQuit = true;
                return(false);
            }
            return(true);
        }