Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.71 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Net;
  7. using System.Net.Sockets;
  8.  
  9. namespace Bus
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.             while (true)
  16.             {
  17.                 Console.WriteLine("Введите начало и конец пути через пробел: ");
  18.                 string message = Console.ReadLine();
  19.  
  20.                 IPEndPoint ip = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8048);
  21.                 Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
  22.                 try
  23.                 {
  24.                     sock.Connect(ip);
  25.                     sock.Send(Encoding.Unicode.GetBytes(message));
  26.                     Console.WriteLine("Начало и конец пути отправленнв на сервер ");
  27.  
  28.                     int bytes = 0;
  29.                     byte[] buff = new byte[256];
  30.                     do
  31.                     {
  32.                         bytes = sock.Receive(buff);
  33.                         message = Encoding.Unicode.GetString(buff, 0, bytes);
  34.                     } while (sock.Available > 0);
  35.  
  36.                     if (message[0] == '1')
  37.                     {
  38.                         Console.WriteLine(message);
  39.                         sock.Send(Encoding.Unicode.GetBytes("1"));
  40.                         Console.WriteLine("Подтверждение отправленно");
  41.                     }
  42.                 }
  43.                 catch(Exception ex)
  44.                 {
  45.                     Console.WriteLine(ex.Message);
  46.                 }
  47.             }
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement