private async Task ConnectToPeers(PeerInformation peer) { try { progressBar.Visibility = Visibility.Visible; UpdatePlayerStatus(peer, " - connecting..."); StreamSocket s = await PeerFinder.ConnectAsync(peer); ConnectedPeer temp = new ConnectedPeer(peer.DisplayName); connectedPeers[temp] = new SocketReaderWriter(s, this); connectedPeers[temp].ReadMessage(); UpdatePlayerStatus(peer, " - ready"); ConnectedPlayers.Items.Add(peer.DisplayName); startGameButton.Visibility = Visibility.Visible; } catch (Exception) { sendInvitationsText.Text = "Cannot connect to " + peer.DisplayName; } // PeerFinder.ConnectAsync aborts PeerWatcher // restart PeerWatcher whether connect failed or succeeded StartPeerWatcher(); }
public void addConnectedPeer(string displayName) { pageTitle.Text = "Connected! Waiting for Host"; ConnectedPeer tempPeer = new ConnectedPeer(displayName); connectedPeers[tempPeer] = this.socket; }
public void AddConnectedPeer(string displayName) { ConnectedPeer temp = new ConnectedPeer(displayName); connectedPeers[temp] = socket; ConnectedPlayers.Items.Add(displayName); }
/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. The Parameter /// property is typically used to configure the page.</param> private async void LoadState(Object navigationParameter, Dictionary <String, Object> pageState) { // Users wait (i.e. watch progress) on this page until the connection has succeeded/failed. backButton.Visibility = Visibility.Collapsed; if (navigationParameter != null) { WaitingForHostParameters parameters = (WaitingForHostParameters)navigationParameter; if (parameters.Peer != null) { pageTitle.Text = "Connecting to " + parameters.Peer.DisplayName.ToString() + "..."; try { StreamSocket socket = await PeerFinder.ConnectAsync(parameters.Peer); pageTitle.Text = "Connected! Waiting for Host..."; this.socket = new SocketReaderWriter(socket, this); ConnectedPeer tempPeer = new ConnectedPeer(parameters.Peer.DisplayName); connectedPeers[tempPeer] = this.socket; PeerFinder.Stop(); StartReading(); } catch (Exception) { pageTitle.Text = "Cannot connect to " + parameters.Peer.DisplayName; PeerFinder.Stop(); } progressBar.Visibility = Visibility.Collapsed; backButton.Visibility = Visibility.Visible; } else if (parameters.Socket != null) { try { this.socket = new SocketReaderWriter(parameters.Socket, this); pageTitle.Text = "Waiting for Host..."; socket.WriteMessage(string.Format("{0} {1}", Constants.OpCodeSendDisplayName, PeerFinder.DisplayName)); PeerFinder.Stop(); StartReading(); } catch (Exception) { pageTitle.Text = "Cannot connect"; PeerFinder.Stop(); } backButton.Visibility = Visibility.Visible; progressBar.Visibility = Visibility.Collapsed; } } }
/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. The Parameter /// property is typically used to configure the page.</param> private async void LoadState(Object navigationParameter, Dictionary<String, Object> pageState) { // Users wait (i.e. watch progress) on this page until the connection has succeeded/failed. backButton.Visibility = Visibility.Collapsed; if (navigationParameter != null) { WaitingForHostParameters parameters = (WaitingForHostParameters)navigationParameter; if (parameters.Peer != null) { pageTitle.Text = "Connecting to " + parameters.Peer.DisplayName.ToString() + "..."; try { StreamSocket socket = await PeerFinder.ConnectAsync(parameters.Peer); pageTitle.Text = "Connected! Waiting for Host..."; this.socket = new SocketReaderWriter(socket, this); ConnectedPeer tempPeer = new ConnectedPeer(parameters.Peer.DisplayName); connectedPeers[tempPeer] = this.socket; PeerFinder.Stop(); StartReading(); } catch (Exception) { pageTitle.Text = "Cannot connect to " + parameters.Peer.DisplayName; PeerFinder.Stop(); } progressBar.Visibility = Visibility.Collapsed; backButton.Visibility = Visibility.Visible; } else if (parameters.Socket != null) { try { this.socket = new SocketReaderWriter(parameters.Socket, this); pageTitle.Text = "Waiting for Host..."; socket.WriteMessage(string.Format("{0} {1}", Constants.OpCodeSendDisplayName, PeerFinder.DisplayName)); PeerFinder.Stop(); StartReading(); } catch (Exception) { pageTitle.Text = "Cannot connect"; PeerFinder.Stop(); } backButton.Visibility = Visibility.Visible; progressBar.Visibility = Visibility.Collapsed; } } }