36 lines
879 B
C#
36 lines
879 B
C#
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}");
|
|
}
|
|
}
|
|
} |