Example #1
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);
            }
        }
Example #2
0
        /// <summary>
        /// Connect to the currently selected session
        /// </summary>
        public void ConnectToSession()
        {
            // Update the UI
            m_Form.SessionStatusLabel.Text = "Connecting...";
            m_Form.Update();

            // Get desired host
            HostInfo SelectedHost = (HostInfo)m_Form.DetectedSessionsListBox.SelectedItem;

            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;
            }
        }
Example #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));
        }