Exemplo n.º 1
0
        /// <summary>
        /// Connect to the currently selected session
        /// </summary>
        public void ConnectToSession()
        {
            // Display connection dialog
            ConnectDialog dialog = new ConnectDialog(this);

            dialog.RemotePort = DefaultPort;

            if (DialogResult.Cancel == dialog.ShowDialog())
            {
                return;
            }

            // Update the UI
            m_Form.SessionStatusLabel.Text = "Connecting...";
            m_Form.Update();

            // Store connection dialog choices
            HostInfo SelectedHost = dialog.SelectedHost;

            if (SelectedHost == null)
            {
                return;
            }

            // Create an application description object to hold the desired
            // host's instance guid.
            ApplicationDescription appDesc = new ApplicationDescription();

            appDesc.GuidInstance = SelectedHost.GuidInstance;

            // Attempt to connect to the selected DirectPlay session. Once we
            // are connected to the session, we will receive DirectPlay messages
            // about session events (like players joining/exiting and received game
            // data). Since we're passing in the "Sync" flag, the Connect call will
            // block until the session is connected or the timeout expires.
            try
            {
                m_Peer.Connect(appDesc,                  // Application description
                               SelectedHost.HostAddress, // Host address
                               m_LocalAddress,           // Local device address
                               null,                     // User connection data (none)
                               ConnectFlags.Sync);       // Flags

                m_SessionName = SelectedHost.SessionName;
                m_Connection  = ConnectionType.Connected;
            }
            catch (Exception ex)
            {
                m_Form.ShowException(ex, "Connect", false);
                return;
            }
        }
Exemplo n.º 2
0
        //---------------------------------------------------------------------
        #endregion // DirectPlay Object Initializations

        #region DirectPlay Event Handlers
        //---------------------------------------------------------------------

        /// <summary>
        /// Event handler for the DirectPlay FindHostResponse message
        /// </summary>
        public void FindHostResponseHandler(object sender, FindHostResponseEventArgs args)
        {
            HostInfo Node = new HostInfo();

            Node.GuidInstance = args.Message.ApplicationDescription.GuidInstance;
            Node.HostAddress  = (Address)args.Message.AddressSender.Clone();
            Node.SessionName  = args.Message.ApplicationDescription.SessionName;

            // If he haven't already seen this host, add the detected session
            // to the stored list
            if (!FoundSessions.Contains(Node))
            {
                FoundSessions.Add(Node);
            }
        }
Exemplo n.º 3
0
        public string SessionName;      // Display name for the session

        /// <summary>
        /// Used by the system collection class
        /// </summary>
        public override bool Equals(object obj)
        {
            HostInfo node = (HostInfo)obj;

            return(GuidInstance.Equals(node.GuidInstance));
        }
Exemplo n.º 4
0
 /// <summary>
 /// Handler for Connect button click
 /// </summary>
 private void ConnectButton_Click(object sender, System.EventArgs e)
 {
     // Save the current settings
     m_SelectedHost = (HostInfo)DetectedSessionsListBox.SelectedItem;
     DialogResult   = DialogResult.OK;
 }