Bars0_j

Untitled

Jan 17th, 2020
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.26 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.Net;
  4. using System.Net.Sockets;
  5.  
  6. namespace Client
  7. {
  8.     class Client
  9.     {
  10.         const int port = 2536; // порт сервера
  11.        const string address = "Ip-adress"; // адрес сервера
  12.  
  13.         static void Main(string[] args)
  14.         {
  15.             Console.WriteLine("Start");
  16.             IPEndPoint ipPoint = new IPEndPoint(IPAddress.Parse(address), port);
  17.  
  18.             Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
  19.             // подключаемся к удаленному хосту
  20.            socket.Connect(ipPoint);
  21.             Console.WriteLine("Connecting");
  22.             while (true)
  23.             {
  24.                 Console.Write("Введите сообщение:");
  25.                 int num = int.Parse(Console.ReadLine());
  26.                 socket.Send(BitConverter.GetBytes(num));
  27.                 byte[] data = new byte[256];
  28.                 socket.Receive(data, data.Length, 0);
  29.                 int result = BitConverter.ToInt32(data);
  30.                 Console.WriteLine("ответ сервера: " + result);
  31.  
  32.             }
  33.                 socket.Shutdown(SocketShutdown.Both);
  34.                 socket.Close();
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment