public void run()
        {
            running = true;

            while (running)
            {
                try
                {
                    IPEndPoint RemoteIPEndPoint = new IPEndPoint(IPAddress.Any, 1138);
                    Byte[]     receiveBytes     = udpClient.Receive(ref RemoteIPEndPoint);

                    HomeTransferServerData data = HomeTransferServerData.createFromUDP(receiveBytes);
                    if (data.type.Equals("close"))
                    {
                        HomeTransferModel.getInstance().removeServer(data);
                    }
                    else
                    {
                        HomeTransferModel.getInstance().addServer(data);
                        if (data.type.Equals("discover"))
                        {
                            HomeTransferController.getInstance().broadcastUDP("response");
                        }
                    }
                    HomeTransferController.getInstance().updateObserver();
                }
                catch (Exception e)
                {
                    Console.WriteLine("UDP listening finished.");
                }
            }
        }
Пример #2
0
 public static HomeTransferController getInstance()
 {
     if (controller == null)
     {
         Console.WriteLine("Controller is made");
         controller = new HomeTransferController();
     }
     return(controller);
 }