From 5f6c3d1c0ca18919e021415104da1556e231751b Mon Sep 17 00:00:00 2001 From: user Date: Wed, 28 Jan 2026 13:56:53 +0400 Subject: [PATCH] update --- Client App/Client App.csproj | 11 ++++++++ Client App/Program.cs | 36 ++++++++++++++++++++++++++ Client-Server Apps.sln | 18 +++++++++++++ Server App/Program.cs | 50 ++++++++++++++++++++++++++++++++++++ Server App/Server App.csproj | 11 ++++++++ 5 files changed, 126 insertions(+) create mode 100644 Client App/Client App.csproj create mode 100644 Client App/Program.cs create mode 100644 Server App/Program.cs create mode 100644 Server App/Server App.csproj diff --git a/Client App/Client App.csproj b/Client App/Client App.csproj new file mode 100644 index 0000000..e3ce20d --- /dev/null +++ b/Client App/Client App.csproj @@ -0,0 +1,11 @@ + + + + Exe + net8.0 + Client_App + enable + enable + + + diff --git a/Client App/Program.cs b/Client App/Program.cs new file mode 100644 index 0000000..a2db0b6 --- /dev/null +++ b/Client App/Program.cs @@ -0,0 +1,36 @@ +using System; +using System.Net.Sockets; +using System.Text; + +class Client +{ + static void Main() + { + TcpClient client = new TcpClient(); + + try + { + client.Connect("127.0.0.1", 8888); + NetworkStream stream = client.GetStream(); + + Console.Write("Текст: "); + string text = Console.ReadLine(); + + byte[] data = Encoding.UTF8.GetBytes(text); + stream.Write(data, 0, data.Length); + + data = new byte[1024]; + int bytes = stream.Read(data, 0, data.Length); + string response = Encoding.UTF8.GetString(data, 0, bytes); + + Console.WriteLine($"Ответ: {response}"); + + stream.Close(); + client.Close(); + } + catch (Exception e) + { + Console.WriteLine($"Ошибка: {e.Message}"); + } + } +} \ No newline at end of file diff --git a/Client-Server Apps.sln b/Client-Server Apps.sln index a4d5a8e..5070b14 100644 --- a/Client-Server Apps.sln +++ b/Client-Server Apps.sln @@ -3,7 +3,25 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.14.36705.20 d17.14 MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Client App", "Client App\Client App.csproj", "{82FF86E4-6714-408E-882F-D636C3E658A4}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server App", "Server App\Server App.csproj", "{A3708F42-6AC7-4828-A5F2-C68B68D6860C}" +EndProject Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {82FF86E4-6714-408E-882F-D636C3E658A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {82FF86E4-6714-408E-882F-D636C3E658A4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {82FF86E4-6714-408E-882F-D636C3E658A4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {82FF86E4-6714-408E-882F-D636C3E658A4}.Release|Any CPU.Build.0 = Release|Any CPU + {A3708F42-6AC7-4828-A5F2-C68B68D6860C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A3708F42-6AC7-4828-A5F2-C68B68D6860C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A3708F42-6AC7-4828-A5F2-C68B68D6860C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A3708F42-6AC7-4828-A5F2-C68B68D6860C}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection diff --git a/Server App/Program.cs b/Server App/Program.cs new file mode 100644 index 0000000..2a81596 --- /dev/null +++ b/Server App/Program.cs @@ -0,0 +1,50 @@ +using System.Net; +using System.Net.Sockets; +using System.Text; + +class Server +{ + static void Main() + { + TcpListener server = new TcpListener(IPAddress.Any, 8888); + + try + { + server.Start(); + Console.WriteLine("Сервер запущен"); + + while (true) + { + TcpClient client = server.AcceptTcpClient(); + NetworkStream stream = client.GetStream(); + + byte[] buffer = new byte[1024]; + int bytes = stream.Read(buffer, 0, buffer.Length); + + string text = Encoding.UTF8.GetString(buffer, 0, bytes); + Console.WriteLine($"Получено: {text}"); + + string response = $"OK: {StrProc(text)}"; + byte[] data = Encoding.UTF8.GetBytes(response); + stream.Write(data, 0, data.Length); + + stream.Close(); + client.Close(); + } + } + catch (Exception e) + { + Console.WriteLine($"Ошибка: {e.Message}"); + } + finally + { + server.Stop(); + } + } + + //18 вариант + private static string StrProc(string str) + { + return str.Replace('y', 'o'); + } +} \ No newline at end of file diff --git a/Server App/Server App.csproj b/Server App/Server App.csproj new file mode 100644 index 0000000..30a4f41 --- /dev/null +++ b/Server App/Server App.csproj @@ -0,0 +1,11 @@ + + + + Exe + net8.0 + Server_App + enable + enable + + +