private void AddFoundServer(DiscoveredServerInfo server) { if (!Application.Current.Dispatcher.CheckAccess()) { Application.Current.Dispatcher.Invoke(new Action(() => AddFoundServer(server))); } if (!FoundServer.Contains(server)) { FoundServer.Add(server); } }
private async Task <bool> DiscoverAndConnectAsync() { Task <DiscoveredServerInfo> task = DiscoveryFinder.DiscoverReturnFirstAsync(); NotifyChange(new String[] { "IsDiscovering", "IsConnectingOrDiscovering" }); Log.i(TAG, "Searching for " + (string)Application.Current.FindResource("AppNameCode") + " clients in local network ", true); DiscoveredServerInfo found = await task; if (found != null) { return(await ConnectToServerAsync(found.ConnectionIP, found.Port, found.ServerGUID)); } Log.i(TAG, "No " + (string)Application.Current.FindResource("AppNameCode") + " clients in local network found", true); return(false); }
private void HandleAnswer(UdpReceiveResult answer, List <DiscoveredServerInfo> liResults, String strSource) { DiscoveryPacket recvPacket = DiscoveryPacket.ReadPacket(answer.Buffer); if (recvPacket.IsValid) { if (recvPacket.IsAnswer() && recvPacket is DiscoveryPacket_Answer recvAnswer) { m_bRemoteMinVersionError = recvAnswer.MinProtocolVer > BBProtocol.CURRENT_PROTOCOL_VERSION; m_bLocalMinVersionError = recvAnswer.MaxProtocolVer < BBProtocol.MIN_PROTOCOL_VERSION; if (!m_bLocalMinVersionError && !m_bRemoteMinVersionError) { DiscoveredServerInfo info = new DiscoveredServerInfo(recvAnswer, answer.RemoteEndPoint.Address); if (!liResults.Contains(info)) { liResults.Add(info); // Only return the server as First Result (to be connected to) if it's the Default Server or no Default has been set if (Properties.Settings.Default.DefaultServer == 0 || info.ServerGUID == Properties.Settings.Default.DefaultServer) { m_wbFirstResult.Post(info); } AddFoundServer(info); Log.d(TAG, "Recveid answer from " + strSource + " - " + info.getDebugString()); } else { Log.d(TAG, "Ignored duplicate answer from " + strSource + " - " + info.getDebugString()); } } else { Log.d(TAG, "Protocolversion not supported in answer from " + strSource); } } else { Log.e(TAG, "Unknown/unexpected packet received from " + answer.RemoteEndPoint); } } else { Log.e(TAG, "Invalid packet received from " + answer.RemoteEndPoint + " - " + recvPacket.ParseError); } }