Advertisement
Guest User

Untitled

a guest
Oct 17th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.32 KB | None | 0 0
  1. public class Client : MonoBehaviour
  2. {
  3.     public Button StartButton;
  4.  
  5.     void Start()
  6.     {
  7.         // print(GetLocalIPAddress());
  8.  
  9.         StartButton.onClick.AddListener(CreateConnection);
  10.     }
  11.  
  12.     void CreateConnection()
  13.     {
  14.         try
  15.         {
  16.             print("Start");
  17.             // Создаем UdpClient для чтения входящих данных
  18.             UdpClient MobileClient = new UdpClient(9999);
  19.  
  20.             IPEndPoint RemoteIpEndPoint = null;
  21.  
  22.             try
  23.             {
  24.                 print("try");
  25.  
  26.                 while (true)
  27.                 {
  28.                     // Ожидание дейтаграммы
  29.                     byte[] receiveBytes = MobileClient.Receive(
  30.                         ref RemoteIpEndPoint);
  31.  
  32.                     // Преобразуем и отображаем данные
  33.                     string returnData = Encoding.UTF8.GetString(receiveBytes);
  34.                     Console.WriteLine(" --> " + returnData.ToString());
  35.                 }
  36.             }
  37.             catch (Exception ex)
  38.             {
  39.                 Console.WriteLine("Возникло исключение: " + ex.ToString() + "\n  " + ex.Message);
  40.             }
  41.         }
  42.         catch (Exception ex)
  43.         {
  44.             print(ex.Message);
  45.         }
  46.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement