update
This commit is contained in:
11
Client App/Client App.csproj
Normal file
11
Client App/Client App.csproj
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<RootNamespace>Client_App</RootNamespace>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
36
Client App/Program.cs
Normal file
36
Client App/Program.cs
Normal file
@@ -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}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,25 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.14.36705.20 d17.14
|
VisualStudioVersion = 17.14.36705.20 d17.14
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
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
|
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
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
|
|||||||
50
Server App/Program.cs
Normal file
50
Server App/Program.cs
Normal file
@@ -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');
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Server App/Server App.csproj
Normal file
11
Server App/Server App.csproj
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
|
<RootNamespace>Server_App</RootNamespace>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
Reference in New Issue
Block a user