Esempio n. 1
0
        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();
        }
Esempio n. 2
0
        public void addConnectedPeer(string displayName)
        {
            pageTitle.Text = "Connected! Waiting for Host";
            ConnectedPeer tempPeer = new ConnectedPeer(displayName);

            connectedPeers[tempPeer] = this.socket;
        }
Esempio n. 3
0
        public void AddConnectedPeer(string displayName)
        {
            ConnectedPeer temp = new ConnectedPeer(displayName);

            connectedPeers[temp] = socket;
            ConnectedPlayers.Items.Add(displayName);
        }
Esempio n. 4
0
        /// <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;
                }
            }
        }
Esempio n. 6
0
        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();
        }
Esempio n. 7
0
 public void AddConnectedPeer(string displayName)
 {
     ConnectedPeer temp = new ConnectedPeer(displayName);
     connectedPeers[temp] = socket;
     ConnectedPlayers.Items.Add(displayName);
 }
 public void addConnectedPeer(string displayName)
 {
     pageTitle.Text = "Connected! Waiting for Host";
     ConnectedPeer tempPeer = new ConnectedPeer(displayName);
     connectedPeers[tempPeer] = this.socket;
 }