Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- using System.Net;
- using System.Net.Sockets;
- namespace Client
- {
- class Client
- {
- const int port = 2536; // порт сервера
- const string address = "Ip-adress"; // адрес сервера
- static void Main(string[] args)
- {
- Console.WriteLine("Start");
- IPEndPoint ipPoint = new IPEndPoint(IPAddress.Parse(address), port);
- Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
- // подключаемся к удаленному хосту
- socket.Connect(ipPoint);
- Console.WriteLine("Connecting");
- while (true)
- {
- Console.Write("Введите сообщение:");
- int num = int.Parse(Console.ReadLine());
- socket.Send(BitConverter.GetBytes(num));
- byte[] data = new byte[256];
- socket.Receive(data, data.Length, 0);
- int result = BitConverter.ToInt32(data);
- Console.WriteLine("ответ сервера: " + result);
- }
- socket.Shutdown(SocketShutdown.Both);
- socket.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment