update
This commit is contained in:
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