static void Main(string[] args)
        {
            LoadMimeTypes();

            // Direct requests to locally stored files.
            string basePath = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            IModule contentModule = new LocalFileModule(string.Format("{0}\\walrus", basePath));

            // Cache files into memory and pre-compress, ideal for static content.
            IModule cacheModule = new CompressedCache(contentModule);

            // Restrict content to a rate of 64 Kbytes per second.
            IModule limiterModule = new StreamLimiter(cacheModule, 1024 * 64);

            ServerConfiguration configuration = new ServerConfiguration();
            Server server = new Server(configuration, cacheModule);

            // Apply the speed restriction to PNG and JPG files.
            server.Modules.Add(MimeTypes.Get("png"), limiterModule);
            server.Modules.Add(MimeTypes.Get("jpg"), limiterModule);

            Console.WriteLine("Server Running");
            while (Console.ReadLine() != "quit")
            {

            }
        }
Beispiel #2
0
        public Server(ServerConfiguration configuration, IModule defaultModule)
        {
            Configuration = configuration;
            Modules = new ServerModules(defaultModule);

            _listener = new HttpListener();
            _listener.Prefixes.Add(configuration.Prefix);
            _listener.Start();

            _worker = new Thread(AcceptRequests);
            _worker.Start();
        }