/// <summary>
/// 初始化实例并开启侦测
/// </summary>
/// <param name="inputClient"></param>
/// <param name="replay"></param>
public GameData(ref TcpClient inputClient, Action<string, byte[]> replay)
{
client = inputClient;
stream = inputClient.GetStream();
ReplyNewMessage = new Action<string, byte[]>(replay);
stopReadFlag = false;
Task.Run(() =>
{
while (true) {
if (stopReadFlag == true) { break; }
//读取数据长度
byte[] buffer = new byte[4];
stream.Read(buffer, 0, 4);
int length = BitConverter.ToInt32(buffer, 0);
//读取正文
buffer = new byte[length];
stream.Read(buffer, 0, length);
string head;
byte[] contant;
BallanceOnline.CombineAndSplitSign.Split(buffer, out head, out contant);
//调用委托处理
ReplyNewMessage(head, contant);
}
});
}