/// <summary> /// Class constructor /// </summary> /// <param name="Config">Server configuration</param> /// <param name="Security">Server credentials</param> /// <param name="PagesDirectory">Location where pages are stored</param> public HttpServer(Configuration Config, Credential Security, string PagesDirectory) { this.ram_stream = null; this.ram_buffer = null; this.ram_used = false; this.server_thread = null; this.listen_socket = null; this.accepted_socket = null; this.is_server_running = false; this.storage_path = PagesDirectory; this.recieve_buffer = null; this.send_buffer = new byte[256]; is_polled = false; data_size = 0; this.server_thread = new Thread(new ThreadStart(run_server)); this.server_config = Config; this.server_credential = Security; this.use_authentication = true; if (!server_config.DhcpEnabled) { NetworkInterface networkInterface = NetworkInterface.GetAllNetworkInterfaces()[0]; networkInterface.EnableStaticIP(server_config.IpAddress, server_config.SubnetMask, server_config.DefaultGateWay); Thread.Sleep(1000); } }
/// <summary> /// Class constructor which initializes used with an external ram 23K640 /// </summary> /// <param name="Connection">Current socket</param> /// <param name="RamBuffer">RamString passed</param> /// <param name="DataSize">Available read size</param> /// <param name="FilesPath">Files storage path</param> public HttpRequest(Socket Connection, RamString RamBuffer, int DataSize, string FilesPath) { this.ram_string = RamBuffer; this.use_ram = true; this.files_path = FilesPath; this.host_address = ((IPEndPoint)Connection.RemoteEndPoint).Address.ToString(); this.connection = Connection; byte[] b = new byte[1]; ram_string.BeginWrite(0); for (int i = 0; i < DataSize; i++) { Connection.Receive(b, 0, b.Length, SocketFlags.None); ram_string.WriteSingle(b[0]); } ram_string.EndWrite(); if (this.ram_string.IndexOf("GET") >= 0) { this.http_method = "GET"; } else if (this.ram_string.IndexOf("POST") >= 0) { this.http_method = "POST"; } else { throw new Exception("Only GET And POST Methods Are Supported"); } this.request_length = this.ram_string.Length; }
/// <summary> /// Class constructor used with 23K640 ram as an external memory recieve buffer /// </summary> /// <param name="Config">Server configuration</param> /// <param name="PagesDirectory">Pages directory</param> /// <param name="RamChipSelectPin">Chip select Pin 23K640</param> /// <param name="RamHoldPin">Hold Pin 23K640</param> public HttpServer(Configuration Config, string PagesDirectory, Cpu.Pin RamChipSelectPin, Cpu.Pin RamHoldPin) { this.ram_stream = new RamStream(RamChipSelectPin, RamHoldPin); this.ram_buffer = new RamString(this.ram_stream); this.ram_used = true; this.server_thread = null; this.listen_socket = null; this.accepted_socket = null; this.is_server_running = false; this.storage_path = PagesDirectory; this.recieve_buffer = null; this.send_buffer = new byte[256]; is_polled = false; data_size = 0; this.server_thread = new Thread(new ThreadStart(run_server)); this.server_config = Config; this.use_authentication = false; if (!server_config.DhcpEnabled) { NetworkInterface networkInterface = NetworkInterface.GetAllNetworkInterfaces()[0]; networkInterface.EnableStaticIP(server_config.IpAddress, server_config.SubnetMask, server_config.DefaultGateWay); Thread.Sleep(1000); } while (!ram_stream_verification()) { ; } }
/// <summary> /// Class constructor /// </summary> /// <param name="buffer">Recieved buffer</param> /// <param name="FilesPath">Server files Location</param> /// <param name="Connection">Current active socket</param> public HttpRequest(byte[] buffer, string FilesPath, Socket Connection) { this.ram_string = null; this.use_ram = false; this.request_buffer = new string(UTF8Encoding.UTF8.GetChars(buffer)); this.files_path = FilesPath; if (this.request_buffer.IndexOf("GET") >= 0) { this.http_method = "GET"; } else if (this.request_buffer.IndexOf("POST") >= 0) { this.http_method = "POST"; } else { throw new Exception("Only GET And POST Methods Are Supported"); } this.request_length = this.request_buffer.Length; this.host_address = ((IPEndPoint)Connection.RemoteEndPoint).Address.ToString(); this.connection = Connection; }