Esempio n. 1
0
    /// <summary>
    /// Socket 断开处理
    /// </summary>
    private void CloseClientSocket(AsyncUserToken userToken)
    {
        try
        {
            if (userToken.ConnectSocket == null)
            {
                return;
            }

            ServerDataManager.instance.SetOffLineByState(userToken);
            Log4Debug(String.Format("客户 {0} 清理链接!", userToken.ConnectSocket.RemoteEndPoint.ToString()));
            //
            userToken.ConnectSocket.Shutdown(SocketShutdown.Both);
            userToken.ConnectSocket.Close();
            Log4Debug("Free Client total:" + userTokenPool.Count());
        }
        catch
        {
        }
        finally
        {
            userTokenPool.RemoveUsed(userToken); //清除在线
            userToken.Init();                    //清除该变量
            userTokenPool.Push(userToken);       //复存该变量
        }
    }