HttpServer
This commit is contained in:
		
						commit
						28de1ebd2d
					
				
							
								
								
									
										25
									
								
								HttpProject.sln
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								HttpProject.sln
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,25 @@ | |||||||
|  |  | ||||||
|  | Microsoft Visual Studio Solution File, Format Version 12.00 | ||||||
|  | # Visual Studio Version 16 | ||||||
|  | VisualStudioVersion = 16.0.28803.352 | ||||||
|  | MinimumVisualStudioVersion = 10.0.40219.1 | ||||||
|  | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HttpProject", "HttpProject\HttpProject.csproj", "{BE5D0786-ACE4-40F1-8E54-3A6C5AFBA5C7}" | ||||||
|  | EndProject | ||||||
|  | Global | ||||||
|  | 	GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||||||
|  | 		Debug|Any CPU = Debug|Any CPU | ||||||
|  | 		Release|Any CPU = Release|Any CPU | ||||||
|  | 	EndGlobalSection | ||||||
|  | 	GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||||||
|  | 		{BE5D0786-ACE4-40F1-8E54-3A6C5AFBA5C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||||||
|  | 		{BE5D0786-ACE4-40F1-8E54-3A6C5AFBA5C7}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||||||
|  | 		{BE5D0786-ACE4-40F1-8E54-3A6C5AFBA5C7}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||||||
|  | 		{BE5D0786-ACE4-40F1-8E54-3A6C5AFBA5C7}.Release|Any CPU.Build.0 = Release|Any CPU | ||||||
|  | 	EndGlobalSection | ||||||
|  | 	GlobalSection(SolutionProperties) = preSolution | ||||||
|  | 		HideSolutionNode = FALSE | ||||||
|  | 	EndGlobalSection | ||||||
|  | 	GlobalSection(ExtensibilityGlobals) = postSolution | ||||||
|  | 		SolutionGuid = {29CC3C79-BE5F-4BAC-A965-B05CD89AEFAE} | ||||||
|  | 	EndGlobalSection | ||||||
|  | EndGlobal | ||||||
							
								
								
									
										6
									
								
								HttpProject/App.config
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								HttpProject/App.config
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,6 @@ | |||||||
|  | <?xml version="1.0" encoding="utf-8" ?> | ||||||
|  | <configuration> | ||||||
|  |     <startup>  | ||||||
|  |         <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" /> | ||||||
|  |     </startup> | ||||||
|  | </configuration> | ||||||
							
								
								
									
										58
									
								
								HttpProject/HttpProject.csproj
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								HttpProject/HttpProject.csproj
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,58 @@ | |||||||
|  | <?xml version="1.0" encoding="utf-8"?> | ||||||
|  | <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||||||
|  |   <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||||||
|  |   <PropertyGroup> | ||||||
|  |     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||||||
|  |     <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||||||
|  |     <ProjectGuid>{BE5D0786-ACE4-40F1-8E54-3A6C5AFBA5C7}</ProjectGuid> | ||||||
|  |     <OutputType>Exe</OutputType> | ||||||
|  |     <RootNamespace>HttpProject</RootNamespace> | ||||||
|  |     <AssemblyName>HttpProject</AssemblyName> | ||||||
|  |     <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion> | ||||||
|  |     <FileAlignment>512</FileAlignment> | ||||||
|  |     <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||||||
|  |     <Deterministic>true</Deterministic> | ||||||
|  |   </PropertyGroup> | ||||||
|  |   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||||||
|  |     <PlatformTarget>AnyCPU</PlatformTarget> | ||||||
|  |     <DebugSymbols>true</DebugSymbols> | ||||||
|  |     <DebugType>full</DebugType> | ||||||
|  |     <Optimize>false</Optimize> | ||||||
|  |     <OutputPath>bin\Debug\</OutputPath> | ||||||
|  |     <DefineConstants>DEBUG;TRACE</DefineConstants> | ||||||
|  |     <ErrorReport>prompt</ErrorReport> | ||||||
|  |     <WarningLevel>4</WarningLevel> | ||||||
|  |   </PropertyGroup> | ||||||
|  |   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||||||
|  |     <PlatformTarget>AnyCPU</PlatformTarget> | ||||||
|  |     <DebugType>pdbonly</DebugType> | ||||||
|  |     <Optimize>true</Optimize> | ||||||
|  |     <OutputPath>bin\Release\</OutputPath> | ||||||
|  |     <DefineConstants>TRACE</DefineConstants> | ||||||
|  |     <ErrorReport>prompt</ErrorReport> | ||||||
|  |     <WarningLevel>4</WarningLevel> | ||||||
|  |   </PropertyGroup> | ||||||
|  |   <ItemGroup> | ||||||
|  |     <Reference Include="System" /> | ||||||
|  |     <Reference Include="System.Core" /> | ||||||
|  |     <Reference Include="System.Xml.Linq" /> | ||||||
|  |     <Reference Include="System.Data.DataSetExtensions" /> | ||||||
|  |     <Reference Include="Microsoft.CSharp" /> | ||||||
|  |     <Reference Include="System.Data" /> | ||||||
|  |     <Reference Include="System.Net.Http" /> | ||||||
|  |     <Reference Include="System.Xml" /> | ||||||
|  |   </ItemGroup> | ||||||
|  |   <ItemGroup> | ||||||
|  |     <Compile Include="Client.cs" /> | ||||||
|  |     <Compile Include="Program.cs" /> | ||||||
|  |     <Compile Include="Properties\AssemblyInfo.cs" /> | ||||||
|  |     <Compile Include="Server.cs" /> | ||||||
|  |   </ItemGroup> | ||||||
|  |   <ItemGroup> | ||||||
|  |     <None Include="App.config" /> | ||||||
|  |   </ItemGroup> | ||||||
|  |   <ItemGroup> | ||||||
|  |     <Content Include="index.html" /> | ||||||
|  |   </ItemGroup> | ||||||
|  |   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||||||
|  | </Project> | ||||||
							
								
								
									
										101
									
								
								HttpProject/Program.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										101
									
								
								HttpProject/Program.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,101 @@ | |||||||
|  | using System; | ||||||
|  | using System.Collections.Generic; | ||||||
|  | using System.Linq; | ||||||
|  | using System.Net; | ||||||
|  | using System.Net.Sockets; | ||||||
|  | using System.Text; | ||||||
|  | using System.Threading.Tasks; | ||||||
|  | using System.IO; | ||||||
|  | using System.Net.Http; | ||||||
|  | using System.Threading; | ||||||
|  | 
 | ||||||
|  | namespace HttpProject | ||||||
|  | { | ||||||
|  | 
 | ||||||
|  |     class Program | ||||||
|  |     { | ||||||
|  | 
 | ||||||
|  |         //static async Task Main(string[] args) | ||||||
|  |         //{ | ||||||
|  |         //    var listener = new HttpListener(); | ||||||
|  |         //    listener.Prefixes.Add("http://localhost:8080/"); //  | ||||||
|  | 
 | ||||||
|  |         //    try | ||||||
|  |         //    { | ||||||
|  |         //        listener.Start(); | ||||||
|  |         //        Console.WriteLine("Сервер запущен. Ожидание подключений..."); | ||||||
|  | 
 | ||||||
|  |         //        while (true) | ||||||
|  |         //        { | ||||||
|  |         //            var context = await listener.GetContextAsync(); | ||||||
|  |         //            HandleRequest(context); | ||||||
|  |         //        } | ||||||
|  |         //    } | ||||||
|  |         //    catch (Exception ex) | ||||||
|  |         //    { | ||||||
|  |         //        Console.WriteLine($"Ошибка: {ex.Message}"); | ||||||
|  |         //    } | ||||||
|  |         //    finally | ||||||
|  |         //    { | ||||||
|  |         //        listener.Close(); | ||||||
|  |         //    } | ||||||
|  |         //} | ||||||
|  | 
 | ||||||
|  |         //static void HandleRequest(HttpListenerContext context) | ||||||
|  |         //{ | ||||||
|  |         //    var request = context.Request; | ||||||
|  |         //    var response = context.Response; | ||||||
|  | 
 | ||||||
|  |         //    Console.WriteLine($"Получен запрос: {request.HttpMethod} {request.Url}"); | ||||||
|  | 
 | ||||||
|  |         //    string responseString = "<html><body><h1>Hello, world!</h1></body></html>"; | ||||||
|  |         //    byte[] buffer = Encoding.UTF8.GetBytes(responseString); | ||||||
|  | 
 | ||||||
|  |         //    response.ContentType = "text/html"; | ||||||
|  |         //    response.ContentLength64 = buffer.Length; | ||||||
|  | 
 | ||||||
|  |         //    using (Stream output = response.OutputStream) | ||||||
|  |         //    { | ||||||
|  |         //        output.Write(buffer, 0, buffer.Length); | ||||||
|  |         //    } | ||||||
|  | 
 | ||||||
|  |         //    response.Close(); | ||||||
|  |         //} | ||||||
|  | 
 | ||||||
|  |         public static void Main() | ||||||
|  |         { | ||||||
|  | 
 | ||||||
|  |             Console.WriteLine("Starting echo server..."); | ||||||
|  | 
 | ||||||
|  |             | ||||||
|  |             | ||||||
|  |                 int port = 1234; | ||||||
|  |                 TcpListener listener = new TcpListener(IPAddress.Any, port); | ||||||
|  |                 listener.Start(); | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |             while (true) | ||||||
|  |             {  | ||||||
|  |                 TcpClient client = listener.AcceptTcpClient(); | ||||||
|  |                 NetworkStream stream = client.GetStream(); | ||||||
|  |                 //StreamWriter writer = new StreamWriter(stream, Encoding.ASCII) { AutoFlush = true }; | ||||||
|  |                 StreamReader reader = new StreamReader(stream, Encoding.UTF8); | ||||||
|  | 
 | ||||||
|  |                 while (true) | ||||||
|  |                 { | ||||||
|  |                     string inputLine = ""; | ||||||
|  |                     while (inputLine != null) | ||||||
|  |                     { | ||||||
|  |                         inputLine = reader.ReadLine(); | ||||||
|  |                         //writer.WriteLine("Echoing string: " + inputLine); | ||||||
|  |                         Console.WriteLine("Echoing string: " + inputLine); | ||||||
|  |                     } | ||||||
|  |                     Console.WriteLine("Server saw disconnect from client."); | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | } | ||||||
							
								
								
									
										36
									
								
								HttpProject/Properties/AssemblyInfo.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								HttpProject/Properties/AssemblyInfo.cs
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,36 @@ | |||||||
|  | using System.Reflection; | ||||||
|  | using System.Runtime.CompilerServices; | ||||||
|  | using System.Runtime.InteropServices; | ||||||
|  | 
 | ||||||
|  | // Общие сведения об этой сборке предоставляются следующим набором | ||||||
|  | // набора атрибутов. Измените значения этих атрибутов для изменения сведений, | ||||||
|  | // связанные с этой сборкой. | ||||||
|  | [assembly: AssemblyTitle("HttpProject")] | ||||||
|  | [assembly: AssemblyDescription("")] | ||||||
|  | [assembly: AssemblyConfiguration("")] | ||||||
|  | [assembly: AssemblyCompany("")] | ||||||
|  | [assembly: AssemblyProduct("HttpProject")] | ||||||
|  | [assembly: AssemblyCopyright("Copyright ©  2024")] | ||||||
|  | [assembly: AssemblyTrademark("")] | ||||||
|  | [assembly: AssemblyCulture("")] | ||||||
|  | 
 | ||||||
|  | // Установка значения False для параметра ComVisible делает типы в этой сборке невидимыми | ||||||
|  | // для компонентов COM. Если необходимо обратиться к типу в этой сборке через | ||||||
|  | // из модели COM задайте для атрибута ComVisible этого типа значение true. | ||||||
|  | [assembly: ComVisible(false)] | ||||||
|  | 
 | ||||||
|  | // Следующий GUID представляет идентификатор typelib, если этот проект доступен из модели COM | ||||||
|  | [assembly: Guid("be5d0786-ace4-40f1-8e54-3a6c5afba5c7")] | ||||||
|  | 
 | ||||||
|  | // Сведения о версии сборки состоят из указанных ниже четырех значений: | ||||||
|  | // | ||||||
|  | //      Основной номер версии | ||||||
|  | //      Дополнительный номер версии | ||||||
|  | //      Номер сборки | ||||||
|  | //      Номер редакции | ||||||
|  | // | ||||||
|  | // Можно задать все значения или принять номера сборки и редакции по умолчанию  | ||||||
|  | // используя "*", как показано ниже: | ||||||
|  | // [assembly: AssemblyVersion("1.0.*")] | ||||||
|  | [assembly: AssemblyVersion("1.0.0.0")] | ||||||
|  | [assembly: AssemblyFileVersion("1.0.0.0")] | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user