void ReceiveBodyData(IAsyncResult result) { try { TMASPkg pack = new TMASPkg(); int len = m_Skt.EndReceive(result); if (len > 0) { pack.bodyIndex += len; if (pack.bodyIndex < pack.bodyLen) { m_Skt.BeginReceive(pack.bodyBuffer, pack.bodyIndex, pack.bodyLen - pack.bodyIndex, SocketFlags.None, new AsyncCallback(ReceiveBodyData), pack ); } else { T msg = TMASTools.DeSerialize <T>(pack.bodyBuffer); ONReceiveMsg(msg); pack.ResetData(); m_Skt.BeginReceive( pack.headBuffer, 0, pack.headLen, SocketFlags.None, new AsyncCallback(ReceiveHeadData), pack ); } } else { OnDisConnected(); Clear(); } } catch (System.Exception) { throw; } }
public void SendMsg(T msg) { byte[] data = TMASTools.PackLenInfo(TMASTools.Serialize <T>(msg)); SendMsg(data); }