コード例 #1
0
        private LocalAccessService()
        {
            NetworkInterface NI = NetworkInterface.GetAllNetworkInterfaces()[0];

            ServerCredentials credentials = new ServerCredentials("mkresz", "admin", "admin");
            ServerConfiguration config = new ServerConfiguration(NI.IPAddress, NI.SubnetMask, NI.GatewayAddress, 80);
            httpServer = new HttpServer(config, credentials, 512, 256, @"\SD");
            httpServer.OnRequestReceived += new OnRequestReceivedDelegate(server_OnRequestReceived);
            httpServer.OnServerError += new OnErrorDelegate(server_OnServerError);
        }
コード例 #2
0
        /// <summary>
        /// constructor
        /// </summary>
        /// <param name="Config">server configuration object</param>
        /// <param name="ReceiveBufferSize">receiving buffer size in bytes</param>
        /// <param name="SendBufferSize">sending buffer size in bytes</param>
        /// <param name="pages_folder">usually @"\SD" which is the sd card directory path</param>
        public HttpServer(ServerConfiguration Config, int ReceiveBufferSize, int SendBufferSize, string pages_folder)
        {
            SERVER_THREAD = null;
            LISTEN_SOCKET = null;
            ACCEPTED_SOCKET = null;
            IS_SERVER_RUNNING = false;
            STORAGE_PATH = pages_folder;
            RECEIVE_BUFFER = new byte[ReceiveBufferSize];
            SEND_BUFFER = new byte[SendBufferSize];
            CONFIG = Config;
            USE_AUTHENTICATION = false;

            if (!File.Exists(STORAGE_PATH + "\\index.txt"))
            {
                FILE_STREAM = new FileStream(STORAGE_PATH + "\\index.txt", FileMode.Create, FileAccess.Write);
                FILE_WRITER = new StreamWriter(FILE_STREAM);
                FILE_WRITER.WriteLine("<html>");
                FILE_WRITER.WriteLine("<head>");
                FILE_WRITER.WriteLine("<title>");
                FILE_WRITER.WriteLine("Index Page");
                FILE_WRITER.WriteLine("</title>");
                FILE_WRITER.WriteLine("<body>");
                FILE_WRITER.WriteLine("<h1 align=center>");
                FILE_WRITER.WriteLine("FILE LIST");
                FILE_WRITER.WriteLine("</h1>");
                FILE_WRITER.WriteLine("</body>");
                FILE_WRITER.WriteLine("</html>");
                FILE_WRITER.Close();
                FILE_STREAM.Close();
            }
            if (!File.Exists(STORAGE_PATH + "\\NotFound.txt"))
            {
                FILE_STREAM = new FileStream(STORAGE_PATH + "\\NotFound.txt", FileMode.Create, FileAccess.Write);
                FILE_WRITER = new StreamWriter(FILE_STREAM);
                FILE_WRITER.WriteLine("<html>");
                FILE_WRITER.WriteLine("<head>");
                FILE_WRITER.WriteLine("<title>");
                FILE_WRITER.WriteLine("Page Not Found");
                FILE_WRITER.WriteLine("</title>");
                FILE_WRITER.WriteLine("<body>");
                FILE_WRITER.WriteLine("<h1 align=center>");
                FILE_WRITER.WriteLine("Page Not Found");
                FILE_WRITER.WriteLine("</h1>");
                FILE_WRITER.WriteLine("</body>");
                FILE_WRITER.WriteLine("</html>");
                FILE_WRITER.Close();
                FILE_STREAM.Close();
            }
        }