Exemplo n.º 1
0
#pragma warning restore RECS0165 // Asynchronous methods should return a Task instead of void

            void OnResolved(IReadOnlyList <IZeroconfHost> hosts)
            {
                lock (discoveredHosts)
                {
                    var newHosts       = new HashSet <Tuple <string, string> >(discoveredHosts);
                    var remainingHosts = new HashSet <Tuple <string, string> >(discoveredHosts);

                    foreach (var host in hosts)
                    {
                        foreach (var service in host.Services)
                        {
                            var keyValue = new Tuple <string, string>(host.DisplayName, service.Value.Name);
                            if (discoveredHosts.Contains(keyValue))
                            {
                                remainingHosts.Remove(keyValue);
                            }
                            else
                            {
                                ServiceFound?.Invoke(this, host);
                                newHosts.Add(keyValue);
                            }
                            if (toRemove.ContainsKey(keyValue))
                            {
                                toRemove.Remove(keyValue);
                            }
                        }
                    }

                    foreach (var service in remainingHosts)
                    {
                        if (toRemove.ContainsKey(service))
                        {
                            //zeroconf sometimes reports missing hosts incorrectly.
                            //after pingsUntilRemove missing hosts reports, we'll remove the service from the list.
                            if (++toRemove[service] > pingsUntilRemove)
                            {
                                toRemove.Remove(service);
                                newHosts.Remove(service);
                                ServiceLost?.Invoke(this, new ZeroconfHost {
                                    DisplayName = service.Item1, Id = service.Item2
                                });
                            }
                        }
                        else
                        {
                            toRemove.Add(service, 0);
                        }
                    }

                    discoveredHosts = newHosts;
                }
            }
Exemplo n.º 2
0
        public void Browse()
        {
            if (servers.Count > 0)
            {
                return;
            }

            var fooServer = new ServerDiscoveryInfo(Dns.GetHostEntry(IPAddress.Loopback), "Foo", "Test");

            servers.Add(fooServer);
            ServiceFound?.Invoke(this, fooServer);

            var barServer = new ServerDiscoveryInfo(Dns.GetHostEntry(Dns.GetHostName()), "Bar", "Test");

            servers.Add(barServer);
            ServiceFound?.Invoke(this, barServer);
        }
Exemplo n.º 3
0
        private void OnStateChangedEvent(UnityMCPeerID arg1, UnityMCSessionState arg2)
        {
            // todo: handle multi-user
            Debug.Log("State: " + arg2.ToString() + " with user: "******"Unexpected state: " + arg2);
                break;
            }
        }
 private void OnServiceFound(string addr)
 {
     _addr = addr;
     ServiceFound?.Invoke(addr);
 }