AddO1f

Seti_3_Client

Apr 2nd, 2017
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1. using System;
  2. using System.Net.Sockets;
  3. using System.Net;
  4. using System.Text;
  5.  
  6. class Program
  7. {
  8.     static void Main(string[] args)
  9.     {
  10.         string message;
  11.         byte[] bytes = new byte[1024];
  12.  
  13.         Console.WriteLine("Для завершения работы клиента пропишите end");
  14.         IPHostEntry ipHost = Dns.GetHostEntry("localhost");
  15.         IPAddress ipAddr = ipHost.AddressList[1];
  16.         IPEndPoint ipEndPoint = new IPEndPoint(ipAddr, 11320);
  17.  
  18.         Socket sender = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
  19.         sender.Connect(ipEndPoint);
  20.  
  21.         while (true)
  22.         {
  23.             message = Console.ReadLine();      
  24.             int bytesSend = sender.Send(Encoding.UTF8.GetBytes(message));
  25.             if (message == "end") { break; }
  26.         }
  27.         sender.Shutdown(SocketShutdown.Both);
  28.         sender.Close();
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment