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>
 /// function for writing credentials into file
 /// </summary>
 /// <param name="FileName">filename only</param>
 /// <param name="Credentials">ServerCredentials object to save</param>
 public static void WriteToFile(string FileName, ServerCredentials Credentials)
 {
     FileStream fs = new FileStream(@"\SD\" + FileName + ".crdn", FileMode.Create, FileAccess.Write);
     StreamWriter Writer = new StreamWriter(fs);
     Writer.WriteLine(Credentials.ServerOwner);
     Writer.WriteLine(Credentials.Key);
     Writer.Close();
     fs.Close();
 }
예제 #3
0
        /// <summary>
        /// constructor
        /// </summary>
        /// <param name="Config">server configuration object</param>
        /// <param name="Credentials">server credentials 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,ServerCredentials Credentials, 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;
            this.CREDENTIALS = Credentials;
            USE_AUTHENTICATION = true;

            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();
            }
        }