Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Client : MonoBehaviour
- {
- public Button StartButton;
- void Start()
- {
- // print(GetLocalIPAddress());
- StartButton.onClick.AddListener(CreateConnection);
- }
- void CreateConnection()
- {
- try
- {
- print("Start");
- // Создаем UdpClient для чтения входящих данных
- UdpClient MobileClient = new UdpClient(9999);
- IPEndPoint RemoteIpEndPoint = null;
- try
- {
- print("try");
- while (true)
- {
- // Ожидание дейтаграммы
- byte[] receiveBytes = MobileClient.Receive(
- ref RemoteIpEndPoint);
- // Преобразуем и отображаем данные
- string returnData = Encoding.UTF8.GetString(receiveBytes);
- Console.WriteLine(" --> " + returnData.ToString());
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine("Возникло исключение: " + ex.ToString() + "\n " + ex.Message);
- }
- }
- catch (Exception ex)
- {
- print(ex.Message);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement