Exemplo n.º 1
0
 public void ReadBody(IAsyncResult ansy)//读身体
 {
     try
     {
         if (!mtcpClient.Connected || !Ns_Read.CanRead)
         {
             Debuger.Log("链接已经被释放");
             return;
         }
         BufferData Msg = (BufferData)ansy.AsyncState;
         int        len = Ns_Read.EndRead(ansy);
         BufOffset += len;
         Debuger.Log("#####################!分割线!#####################");
         Debuger.Log("Body读到字节数:" + len);
         Debuger.Log("Body总共读的字节数:" + BufOffset);
         if (len == 0)
         {
             Debuger.Log("读到0 服务器是否已经断开客户端连接");
         }
         else if (BufOffset == Msg.Length)
         {
             ReadDATA(Msg);
         }
         else
         {
             Debuger.Log("还没读完 继续读body");
             StartReadBody(Msg);//数据还没读完继续读身体
         }
     }
     catch (Exception ex)
     {
         Debuger.LogRed("网络层读取异常 " + ex.Message + " " + ex.StackTrace);
         return;
     }
 }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if ((Time_XinTiao += Time.deltaTime) > Time_XinTiao_JianGe)
        {
            Time_XinTiao = 0;
            if (KWXFrom.GetIns.GameCmd != null)
            {
                Debuger.LogRed("发送心跳包");
                KWXFrom.GetIns.GameCmd.SendHeartBeat(new CMD_HeartBeat()
                {
                });
            }
        }
        if (IsJianCeNet)
        {
            if (Application.loadedLevelName == "Room" && NET_KWX.Instance_.mtcpClient != null && NET_KWX.Instance_.GetCurSTATE == CurSocket.Game_ && NET_KWX.Instance_.mtcpClient.Connected == false) //当在游戏中断线时
            {
                if (Application.internetReachability != NetworkReachability.NotReachable)                                                                                                             //当网络可用时
                {
//                     Debuger.LogRed("断线重连");
//                     IsJianCeNet = false;
//                     GameStart = null;
//                     CMD_Login LOGINitem = new CMD_Login() { UserID = GameManage.GetInstan.LoginUserID, Password = GameManage.GetInstan.LoginPassWord, WeiXinCode = 0 };
//                     KWXFrom.GetIns.LoginCmd.SendLoginGame(LOGINitem, null);
                }
                else
                {
                    Debuger.LogRed("网络不可用");
                }
            }
        }
    }