Ejemplo n.º 1
0
        private async void SearchForAvailableServers(CancellationToken cancelationToken, bool shouldReturnOnFirstOccurrence = true)
        {
            var udpClient = new UdpClient(DiscoveryPort);

            var availableServers = new List <string>();

            while (true)
            {
                try
                {
                    cancelationToken.ThrowIfCancellationRequested();

                    IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);

                    var result = await udpClient.ReceiveAsync();

                    byte[] receivedBytes = result.Buffer;

                    if (receivedBytes != null)
                    {
                        var data = Encoding.ASCII.GetString(receivedBytes);

                        Debug.Log("Message Received" + data.ToString());
                        Debug.Log("Address IP Sender" + result.RemoteEndPoint.ToString());

                        var splittedData = data.Split(':');

                        if (splittedData.Length == 2)
                        {
                            var magic = splittedData[0];

                            if (magic == MagicId)
                            {
                                var ip = result.RemoteEndPoint.Address.ToString();

                                availableServers.Add(ip);

                                if (shouldReturnOnFirstOccurrence)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Debug.Log(e.ToString());
                    break;
                }
            }

            DiscoveryFinished?.Invoke(availableServers);

            udpClient.Close();
            udpClient.Dispose();
        }
Ejemplo n.º 2
0
 private static void OnBluetoothAdapterActionDiscoveryFinished()
 {
     DiscoveryFinished?.Invoke();
 }
Ejemplo n.º 3
0
 // Fired when Bluetooth discovery is finished
 private void JavaDiscoveryFinishedHandler(string empty)
 {
     DiscoveryFinished?.Invoke();
 }