コード例 #1
0
        /// <summary>
        /// Force the communicator to sever it's connection.
        /// </summary>
        public void Disconnect()
        {
            lock (this)
            {
                try
                {
                    Connected = false;

                    if (pinger != null)
                    {
                        pinger.Running = false;
                    }

                    if (keepAliveTimer != null)
                    {
                        keepAliveTimer.Dispose();
                    }

                    if (timerThread != null)
                    {
                        timerThread.Interrupt();
                    }

                    if (session != null)
                    {
                        session.destroy_async(new Destroy_Callback());
                    }

                    if (router != null)
                    {
                        router.destroySession_async(new GameRouterDestroySession_Callback());
                    }

                    if (logger != null)
                    {
                        logger.Close();
                    }

                    DestroyAdapter();
                    DestroyCommunicator();
                }
                catch (System.Exception e)
                {
                    logger.Error(
                        "Unexpected error in the Disconnect() method: {0}", e);
                }
                finally
                {
                    pinger         = null;
                    keepAliveTimer = null;
                    session        = null;
                    sessionOneway  = null;
                    router         = null;
                    auth           = null;
                    timerThread    = null;
                    logger         = null;
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Connect to the game server using the stored properties.
        /// </summary>
        /// <returns>True if the connection was successful; false otherwise.</returns>
        public bool Connect()
        {
            if (logger == null)
            {
                if (LogFile == null)
                {
                    LogFile = "GameCommunicator.log";
                }

                logger = new Logger(LogFile);
            }

            if (Connected)
            {
                // Already connected, so sever the connection and re-create it.
                Disconnect();
            }

            bool result = false;

            lock (this)
            {
                try
                {
                    CreateCommunicator();
                    auth = CreateAuthProxy();

                    CreateAdapter();

                    category = router.getCategoryForClient();

                    Connected = true;

                    result = true;
                }
                catch (Ice.Exception e)
                {
                    logger.Error("Connect() Ice.Exception: {0}", e);
                }
                catch (System.Exception e)
                {
                    logger.Error("Connect() System.Exception: {0}", e);
                }
            }

            return(result);
        }