コード例 #1
0
ファイル: MainForm.cs プロジェクト: sankalpshere/projects
        /// <summary>
        /// Function to create OppComm Client
        /// </summary>
        /// <returns></returns>
        private OppCommClient CreateOppCommClient()
        {
            OppCommClient client = client = new OppCommClient(applicationID, _clientPort);
            client.OnJoined += new JoinedEventHandler(client_OnJoined);
            client.OnLeave += new LeaveEventHandler(client_OnLeave);
            client.Start();

            logAndDisplay("Attempting to locate game host");

            return client;
        }
コード例 #2
0
ファイル: MainForm.cs プロジェクト: sankalpshere/projects
        /// <summary>
        /// Called when Session request is accepted by client.
        /// MAC layer connection establishment is successful.
        /// </summary>
        /// <param name="neighbor"></param>
        /// <param name="sessionID"></param>
        private void NeighborJoined(string neighbor, string sessionID)
        {
            logAndDisplay("Switched to session to find " + neighbor);

            //Start OppCommClient
            _oppComm = CreateOppCommClient();

            //Define event handlers
            InitializeOppComm();

            //Trying to start UDP/IP Communication by sending periodic UDP Invitation broadcasts
            StartInvitationTimer(neighbor, sessionID);
        }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: sankalpshere/projects
        /// <summary>
        /// This function is called once best neighbor is selected for commmunication.
        /// </summary>
        /// <param name="bestPlayer"></param>
        private void ContactNeighbor(string bestPlayer)
        {
            string sessionSSID = null;

            StartTime = DateTime.Now.Ticks;
            sessionSSID = oppCommHandler.SetNeighbor(bestPlayer, OppCommAppID);
            MiddleTime = DateTime.Now.Ticks;

            if (string.IsNullOrEmpty(sessionSSID) == false)
            {
                logAndDisplay("Switched to session to find " + bestPlayer);

                //Stopping gameStarter thread if it is running
                StopGamestarterTimer();

                //Become host of the game and create OppCommListener
                _oppComm = CreateOppCommListener();

                //define event handlers
                InitializeOppComm();

                //start probing for neighbors
                StartInvitationTimer(bestPlayer, sessionSSID);
            }
            else //If failed to contact neighbor or switch to session, re-initiate the gameStarter thread
            {
                bool startTimer = false;
                lock (oppCommHandler.OppcommHandlerStateLock)
                {
                    startTimer = oppCommHandler.OppcommHandlerState == SessionState.WaitingForSessionRequest;
                }
                if (startTimer == true)
                    StartGameStarterTimer();
            }
        }