50 lines
1.2 KiB
C#
50 lines
1.2 KiB
C#
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');
|
|
}
|
|
} |