Пример #1
0
        public void Close()          //断开该Agent的连接
        {
            if (Interlocked.Increment(ref closeReq) != 1)
            {
                return;
            }

            if (isClose)
            {
                return;
            }
            isClose = true;

            LogHelper.Log("Agent", "CloseAgent");
            if (mSocket != null && mSocket.Connected)
            {
                Debug.LogError("CloseSocket");
                try
                {
                    mSocket.Shutdown(SocketShutdown.Both);
                    mSocket.Close();
                }
                catch (Exception exception)
                {
                    Debug.LogError(Util.FlattenException(exception));
                    //Util.PrintStackTrace();
                }
            }
            mSocket = null;

            if (actor != null)
            {
                actor.SendMsg(string.Format("close"));
            }

            //watchDog.Close(id);
            ClosePlayerActor(id);
            if (mSocket != null)
            {
                var ip = mSocket.RemoteEndPoint as IPEndPoint;
                LogHelper.LogClientLogout(string.Format("ip={0}", ip.Address));
            }
            if (server != null)
            {
                server.RemoveAgent(this);
            }
            if (udpAgent != null)
            {
                udpAgent.Close();
            }
        }