void Start() { waitMatchObj.SetActive(false); TcpPB.Instance().mes_request_match_result = Message_Reauest_Match_Result; TcpPB.Instance().mes_cancel_match_result = Message_Cancel_Match_Result; TcpPB.Instance().mes_enter_battle = Message_Enter_Battle; }
void Start() { Screen.sleepTimeout = SleepTimeout.NeverSleep; Application.targetFrameRate = 30; NetGlobal.Instance(); TcpPB.Instance().mes_login_result = Message_Login_Result; waitTip.SetActive(false); }
private void ReceiveMessage(object clientSocket) { Socket myClientSocket = (Socket)clientSocket; string _socketIp = myClientSocket.RemoteEndPoint.ToString().Split(':')[0]; LogManage.Instance.AddLog("有客户端连接:" + _socketIp); dic_clientSocket[_socketIp] = myClientSocket; bool _flag = true; byte[] resultData = new byte[1024]; while (isRun && _flag) { try { // LogManage.Instance.AddLog("_socketName是否连接:" + myClientSocket.Connected); //通过clientSocket接收数据 if (myClientSocket.Poll(1000, SelectMode.SelectRead)) { throw new Exception("客户端关闭了1~"); } int _size = myClientSocket.Receive(resultData); if (_size <= 0) { throw new Exception("客户端关闭了2~"); } byte packMessageId = resultData[PackageConstant.PackMessageIdOffset]; //消息id (1个字节) Int16 packlength = BitConverter.ToInt16(resultData, PackageConstant.PacklengthOffset); //消息包长度 (2个字节) int bodyDataLenth = packlength - PackageConstant.PacketHeadLength; byte[] bodyData = new byte[bodyDataLenth]; Array.Copy(resultData, PackageConstant.PacketHeadLength, bodyData, 0, bodyDataLenth); TcpPB.Instance().AnalyzeMessage((PBCommon.CSID)packMessageId, bodyData, _socketIp); } catch (Exception ex) { LogManage.Instance.AddLog("接收客户端数据异常:" + ex.Message); _flag = false; break; } } CloseClientTcp(_socketIp); }
private void ReceiveMessage() { while (isRun) { try { if (!clientSocket.Connected) { throw new Exception("tcp客户端关闭了~~~"); } // if (clientSocket.Poll(clientSocket.ReceiveTimeout,SelectMode.SelectRead)) { // throw new Exception("客户端关闭了1~"); // } //通过clientSocket接收数据 int _size = clientSocket.Receive(result); if (_size <= 0) { throw new Exception("客户端关闭了2~"); } byte packMessageId = result[PackageConstant.PackMessageIdOffset]; //消息id (1个字节) Int16 packlength = BitConverter.ToInt16(result, PackageConstant.PacklengthOffset); //消息包长度 (2个字节) int bodyDataLenth = packlength - PackageConstant.PacketHeadLength; byte[] bodyData = new byte[bodyDataLenth]; Array.Copy(result, PackageConstant.PacketHeadLength, bodyData, 0, bodyDataLenth); TcpPB.Instance().AnalyzeMessage((PBCommon.SCID)packMessageId, bodyData); } catch (Exception ex) { Debug.Log("接收服务端数据异常:" + ex.Message); EndClient(); break; } } }
void OnDestroy() { TcpPB.Instance().mes_login_result = null; }
void OnDestroy() { TcpPB.Instance().mes_request_match_result = null; TcpPB.Instance().mes_cancel_match_result = null; TcpPB.Instance().mes_enter_battle = null; }