12/29/09 sky: changed visibility to public 12/29/09 sky: modified CreateSocketBindAndListen: added socket option ReuseAddress to prevent false port conflicts with freshly released ports in TIME_WAIT state. In a testing scenario we may be creating and disposing many servers in rapid succession. Default socket behaviour will send the closed socket into the TIME_WAIT state, a sort of cooldown period, making it unavaible. By setting ReuseAddress we are telling winsock to accept the binding event if the socket is in TIME_WAIT. 12/29/09 sky: modified Start: replaced hard coded reference to loopback with instance field _ipAddress and removed the try/catch implicit rollover to ipv6. 12/29/09 sky: modified RootUrl: added support for hostname and arbitrary IP address 01/01/10 sky: added support for relative paths to constructor
Inheritance: System.MarshalByRefObject
        public static int Main(string[] args)
        {
            // parse arguments
            if (args.Length != 2) {
                System.Console.WriteLine("Usage: Cassini.exe [port] [path]");
                return 1;
            }
            int port = Int32.Parse(args[0]);
            string physicalPath = args[1];

            // start server
            Server server = new Server(port, "/", physicalPath, false);
            server.Start();

            // loop until forever
            while (true) {
                // TODO: maybe something to break out earlier?
                Thread.Sleep(60000);
            }

            // stop server
            server.Stop();

            return 0;
        }
Exemple #2
0
        /// <summary>
        /// Browser initialization
        /// </summary>
        static Browser()
        {
            // Get the path to the application
            var physicalPath = GetPhysicalPath();

            // Update database file configuration in the boo file
            UpdateConfiguraiton(physicalPath);

            // Initialize the web server
            WebServer = new Server(Port, "/", physicalPath);
        }
Exemple #3
0
        public void Configure(Server server, int port, string virtualPath, string physicalPath) {
            _server = server;

            _port = port;
            _installPath = null;
            _virtualPath = virtualPath;

            _lowerCasedVirtualPath = CultureInfo.InvariantCulture.TextInfo.ToLower(_virtualPath);
            _lowerCasedVirtualPathWithTrailingSlash = virtualPath.EndsWith("/", StringComparison.Ordinal) ? virtualPath : virtualPath + "/";
            _lowerCasedVirtualPathWithTrailingSlash = CultureInfo.InvariantCulture.TextInfo.ToLower(_lowerCasedVirtualPathWithTrailingSlash);
            _physicalPath = physicalPath;
            _physicalClientScriptPath = HttpRuntime.AspClientScriptPhysicalPath + "\\";
            _lowerCasedClientScriptPathWithTrailingSlash = CultureInfo.InvariantCulture.TextInfo.ToLower(HttpRuntime.AspClientScriptVirtualPath + "/");
        }
Exemple #4
0
        static void Main(string[] args)
        {
            if (args.Length != 5)
            {
                Console.WriteLine("usage: m2net.AspNetHandler.exe senderId subAddr pudAddr physicalDir virtualDir");
                return;
            }

            string sender_id = args[0];
            string sub_addr = args[1];
            string pub_addr = args[2];
            string dir = args[3];
            string virt = args[4];

            if (!Directory.Exists(dir))
            {
                Console.WriteLine("Physical directory '{0}' does not exist.", dir);
                return;
            }

            Connection conn;
            try
            {
                conn = new Connection(sender_id, sub_addr, pub_addr);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Could not create Mongrel2 connection: " + ex.Message);
                return;
            }

            Server srv;
            try
            {
                srv = new Server(conn, virt, dir);
            }
            catch(Exception ex)
            {
                Console.WriteLine("Could not create ASP.NET server: " + ex.Message);
                return;
            }

            srv.Start();

            Console.WriteLine("Press enter to exit m2net.AspNetHandler.");
            Console.ReadLine();

            srv.Stop();
        }
Exemple #5
0
        public override bool Start()
        {
            base.Start();

            var di = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory + "\\www");

            if (!di.Exists)
            {
                di.CreateSubdirectory("www");
            }

            _server = new Server(Connection.Port, "/", di.FullName);

            _server.Start();
            return(true);
        }
        static void Main(string[] args)
        {
            ParseArgs(args);

              var mutex = new Mutex(false, "mycassini" + _portNumber);
              var mutex2 = new Mutex(false, "mycassinirunning" + _portNumber);

              if (_appPath == "stop")
              {
            mutex.WaitOne();
            mutex2.WaitOne();

            mutex2.ReleaseMutex();
            mutex.ReleaseMutex();
            return;
              }

              _server = new Cassini.Server(_portNumber, _virtRoot, _appPath);

              try
              {
            mutex2.WaitOne();
            _server.Start();
              }
              catch (Exception er)
              {
            Console.WriteLine(er);
              }

              while (mutex.WaitOne(0))
              {
            mutex.ReleaseMutex();
            Thread.Sleep(50);
              }

              mutex2.ReleaseMutex();
        }
Exemple #7
0
        void Stop()
        {
            try {
                if (_server != null)
                    _server.Stop();
            }
            catch {
            }
            finally {
                _server = null;
            }

            Close();
        }
Exemple #8
0
        void Start()
        {
            _appPath = appDirTextBox.Text;
            if (_appPath.Length == 0 || !Directory.Exists(_appPath)) {
                ShowError("Invalid Application Directory");
                appDirTextBox.SelectAll();
                appDirTextBox.Focus();
                return;
            }

            _portString = portTextBox.Text;
            int portNumber = -1;
            try {
                portNumber = Int32.Parse(_portString);
            }
            catch {
            }
            if (portNumber <= 0) {
                ShowError("Invalid Port");
                portTextBox.SelectAll();
                portTextBox.Focus();
                return;
            }

            _virtRoot = vrootTextBox.Text;
            if (_virtRoot.Length == 0 || !_virtRoot.StartsWith("/")) {
                ShowError("Invalid Virtual Root");
                vrootTextBox.SelectAll();
                vrootTextBox.Focus();
                return;
            }

            try {
                _server = new Server(portNumber, _virtRoot, _appPath);
                _server.Start();
            }
            catch {
                ShowError(
                    "Cassini Managed Web Server failed to start listening on port " + portNumber + ".\r\n" +
                    "Possible conflict with another Web Server on the same port.");
                portTextBox.SelectAll();
                portTextBox.Focus();
                return;
            }

            startButton.Enabled = false;
            appDirTextBox.Enabled = false;
            portTextBox.Enabled = false;
            vrootTextBox.Enabled = false;
            browseLabel.Visible = true;
            browseLink.Text = GetLinkText();
            browseLink.Visible = true;
            browseLink.Focus();
        }
Exemple #9
0
        public void Configure(Server server, int port, String virtualPath, String physicalPath, String installPath)
        {
            _server = server;

            _port = port;
            _virtualPath = virtualPath;
            _lowerCasedVirtualPath = CultureInfo.InvariantCulture.TextInfo.ToLower(_virtualPath);
            _lowerCasedVirtualPathWithTrailingSlash = virtualPath.EndsWith("/") ? virtualPath : virtualPath + "/";
            _lowerCasedVirtualPathWithTrailingSlash = CultureInfo.InvariantCulture.TextInfo.ToLower(_lowerCasedVirtualPathWithTrailingSlash);
            _physicalPath = physicalPath;
            _installPath = installPath;
            _physicalClientScriptPath = installPath + "\\asp.netclientfiles\\";

            String version4 = FileVersionInfo.GetVersionInfo(typeof(HttpRuntime).Module.FullyQualifiedName).FileVersion;
            String version3 = version4.Substring(0, version4.LastIndexOf('.'));
            _lowerCasedClientScriptPathWithTrailingSlashV10 = "/aspnet_client/system_web/" + version4.Replace('.', '_') + "/";
            _lowerCasedClientScriptPathWithTrailingSlashV11 = "/aspnet_client/system_web/" + version3.Replace('.', '_') + "/";

            _onSocketAccept = new WaitCallback(OnSocketAccept);
            _onStart = new WaitCallback(OnStart);

            // start watching for app domain unloading
            _onAppDomainUnload = new EventHandler(OnAppDomainUnload);
            Thread.GetDomain().DomainUnload += _onAppDomainUnload;
        }
Exemple #10
0
 internal Connection(Server server, m2net.Request mongrel2Request)
 {
     _server          = server;
     _mongrel2Request = mongrel2Request;
 }
Exemple #11
0
 private void OnAppDomainUnload(object unusedObject, EventArgs unusedEventArgs)
 {
     Thread.GetDomain().DomainUnload -= this._onAppDomainUnload;
     if (!this._stopped)
     {
         this.Stop();
         this._server.Restart();
         this._server = null;
     }
 }
Exemple #12
0
 internal Connection(Server server, Socket socket)
 {
     _server = server;
     _socket = socket;
 }
Exemple #13
0
        private void OnAppDomainUnload(Object unusedObject, EventArgs unusedEventArgs)
        {
            Thread.GetDomain().DomainUnload -= _onAppDomainUnload;

            if (_stopped)
                return;

            Stop();

            _server.Restart();
            _server = null;
        }
Exemple #14
0
 public void Start()
 {
     _server = new Server(_port, "/", _path);
     _server.Start();
 }
 public static void InitializeBrowser()
 {
     WebServer = new Server(Port, "/", WebSiteFileLocation.get_physical_path());
     
     WebServer.Start();            
 }
Exemple #16
0
 internal Connection(Server server, Socket socket)
 {
     _server = server;
     _socket = socket;
 }
        private void CassiniServer_Load(object sender, EventArgs e)
        {
            try
            {
                this.SizeChanged += new System.EventHandler(this.Form1_SizeChanged);

                Random random = new Random();
                Port = random.Next(1000, 65535);
                virtualPath = "/";
                physicalPath = Application.StartupPath.Substring(0, Application.StartupPath.LastIndexOf("\\"));
                server = new Server(Port, VirtualPath, PhysicalPath);
                server.Start();

                linkLabel1.Text = "http://localhost:" + port;
                textBox1.Text = port.ToString();
                textBox2.Text = virtualPath;
                textBox3.Text = physicalPath;
                linkLabel1_LinkClicked(null, null);

                notifyIcon1.Text = physicalPath;

                this.Visible = false;
                this.notifyIcon1.Visible = true;

                this.notifyIcon1.BalloonTipIcon = ToolTipIcon.Info;
                this.notifyIcon1.BalloonTipTitle = physicalPath;
                this.notifyIcon1.BalloonTipText = "http://localhost:" + port;
                this.notifyIcon1.ShowBalloonTip(2000);
            }
            catch(Exception ex)
            {
                // MessageBox.Show(this, "请将该文件考到网站的Bin目录在运行", "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                // button1_Click(sender, e);
                MessageBox.Show(this, ex.ToString(), "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                button1_Click(sender, e);
            }
        }
Exemple #18
0
 public void Configure(Server server, int port, string virtualPath, string physicalPath, string installPath)
 {
     this._server = server;
     this._port = port;
     this._virtualPath = virtualPath;
     this._lowerCasedVirtualPath = CultureInfo.InvariantCulture.TextInfo.ToLower(this._virtualPath);
     this._lowerCasedVirtualPathWithTrailingSlash = virtualPath.EndsWith("/") ? virtualPath : (virtualPath + "/");
     this._lowerCasedVirtualPathWithTrailingSlash = CultureInfo.InvariantCulture.TextInfo.ToLower(this._lowerCasedVirtualPathWithTrailingSlash);
     this._physicalPath = physicalPath;
     this._installPath = installPath;
     this._physicalClientScriptPath = installPath + @"\asp.netclientfiles\";
     string fileVersion = FileVersionInfo.GetVersionInfo(typeof(HttpRuntime).Module.FullyQualifiedName).FileVersion;
     string str2 = fileVersion.Substring(0, fileVersion.LastIndexOf('.'));
     this._lowerCasedClientScriptPathWithTrailingSlashV10 = "/aspnet_client/system_web/" + fileVersion.Replace('.', '_') + "/";
     this._lowerCasedClientScriptPathWithTrailingSlashV11 = "/aspnet_client/system_web/" + str2.Replace('.', '_') + "/";
     this._onSocketAccept = new WaitCallback(this.OnSocketAccept);
     this._onStart = new WaitCallback(this.OnStart);
     this._onAppDomainUnload = new EventHandler(this.OnAppDomainUnload);
     Thread.GetDomain().DomainUnload += this._onAppDomainUnload;
 }
Exemple #19
0
		/// <summary>
		/// Starts the web server using the specified web project path. Note 
		/// that the path must be absolute. 
		/// </summary>
		/// <param name="webApplicationAbsolutePath">The web application absolute path.</param>
		public static void StartWebServer(string webApplicationAbsolutePath)
		{
			if (!Directory.Exists(webApplicationAbsolutePath))
			{
				throw new ApplicationException("Cannot start web server as the path could not be found. " + 
					"Check if the following folder exists: " + webApplicationAbsolutePath);
			}

			server = new Server(88, VirtualDir, webApplicationAbsolutePath);
			server.Start();

			started = true;
		}
Exemple #20
0
 internal Connection(Server server, m2net.Request mongrel2Request)
 {
     _server = server;
     _mongrel2Request = mongrel2Request;
 }
Exemple #21
0
 public Request(Server server, Host host, Connection connection)
     : base(String.Empty, String.Empty, null)
 {
     _server = server;
     _host = host;
     _connection = connection;
 }
        public static void initialise_local_Web_server()
        {
            WebServer = new Server(Port, "/", WebSiteFileLocation.get_physical_path());

            WebServer.Start();
        }