public void ReadData() { // lock(Serialization.lockObject) int ReiveBufLength = clientSocket.ReceiveData(BigRecivebuffer); int msgcount = 0; if (ReiveBufLength > 4) { MemoryStream ms = new MemoryStream(BigRecivebuffer, 0, ReiveBufLength); BinaryReader br = new BinaryReader(ms); int currentIndex = 0; while (currentIndex + 4 < ReiveBufLength) { int len = br.ReadInt32(); byte[] result = br.ReadBytes(len); MemoryStream Tms = new MemoryStream(result); DS_protocol.p_AllMsg p_allMsg = Serializer.Deserialize <DS_protocol.p_AllMsg>(Tms); NetCommon.HandleData(this, p_allMsg); msgcount++; currentIndex += 4 + len; } } // Console.WriteLine("recive , ReiveBufLength " + (ReiveBufLength + 4) + " Count " + msgcount); }
public void Update() { CurrentRecive = 0; CurrentSend = 0; lock (server.clients) { TempMsg.Clear(); TempMsgConenct.Clear(); foreach (Client client in server.clients.Values) { UnityEngine.Profiling.Profiler.BeginSample("Socket::RecordData"); ReiveBufLength = server.ReceiveData(client.acceptSocket, BigRecivebuffer); UnityEngine.Profiling.Profiler.EndSample(); if (ReiveBufLength != 0) { CurrentRecive += ReiveBufLength + 4; UnityEngine.Profiling.Profiler.BeginSample("RecordData"); client.RecordData(BigRecivebuffer, ReiveBufLength, TempMsg, TempMsgConenct); UnityEngine.Profiling.Profiler.EndSample(); } } for (int nLoop = 0; nLoop < TempMsg.Count; ++nLoop) { UnityEngine.Profiling.Profiler.BeginSample("RecordData::HandleData"); NetCommon.HandleData(TempMsgConenct[nLoop], TempMsg[nLoop]); UnityEngine.Profiling.Profiler.EndSample(); } UnityEngine.Profiling.Profiler.BeginSample("client.SendData"); foreach (Client client in server.clients.Values) { CurrentSend += client.SendData(); } UnityEngine.Profiling.Profiler.EndSample(); } if (gameServer.GetRoom(0).gameMap.GetFrame() > 50) { if (MaxRecive < CurrentRecive) { MaxRecive = CurrentRecive; } if (MaxSend < CurrentSend) { MaxSend = CurrentSend; } } ReciveTotal += CurrentRecive; SendTotal += CurrentSend; }
void DecodData() { byte[] bytes = NetCommon.Decode(ref ReceiveCache); if (bytes == null) { return; } p_AllMsg p_AllMsg = new p_AllMsg(); p_AllMsg = Serialization.DeserializeData(bytes); NetCommon.HandleData(connectionID, p_AllMsg); DecodData(); }
public void RecordData(byte[] data, int length, List <DS_protocol.p_AllMsg> TMsgs, List <int> TempMsgConenct) { if (data != null && length > 4) { MemoryStream ms = new MemoryStream(data, 0, length); BinaryReader br = new BinaryReader(ms); int currentIndex = 0; while (currentIndex + 4 < length) { int len = br.ReadInt32(); byte[] result = br.ReadBytes(len); MemoryStream Tms = new MemoryStream(result); DS_protocol.p_AllMsg p_allMsg = null; try { UnityEngine.Profiling.Profiler.BeginSample("RecordData::Deserialize"); p_allMsg = Serializer.Deserialize <DS_protocol.p_AllMsg>(Tms); UnityEngine.Profiling.Profiler.EndSample(); } catch (Exception) { return; } if (p_allMsg.type != (int)CmdType.ASKFRAME) { UnityEngine.Profiling.Profiler.BeginSample("RecordData::HandleData"); NetCommon.HandleData(connectionID, p_allMsg); UnityEngine.Profiling.Profiler.EndSample(); } else { TempMsgConenct.Add(connectionID); TMsgs.Add(p_allMsg); } currentIndex += len + 4; } } }