public bool SendStringCheck(byte command, string text) { try { //byte[] sendb = System.Text.Encoding.UTF8.GetBytes(text); //byte[] part3_length = System.Text.Encoding.UTF8.GetBytes(sendb.Length.ToString()); //byte[] b = new byte[2 + part3_length.Length + sendb.Length]; //b[0] = command; //b[1] = (byte)part3_length.Length; //part3_length.CopyTo(b, 2); //扩充 第四部分数据(待发送的数据)的长度,扩充到b数组第三位开始的后面 //sendb.CopyTo(b, 2 + part3_length.Length); //扩充 第四部分数据实际的数据,扩充到b数组第三部分结尾后面... byte[] b = MyGameClientHelper.CodingProtocol(command, text); int count = (b.Length <= 40960 ? b.Length / 40960 : (b.Length / 40960) + 1); if (count == 0) { //判定数据长度,,实际指的是大小是不是小于40kb,,, tcpClient.Client.Send(b); } else { for (int i = 0; i < count; i++) { int zz = b.Length - (i * 40960) > 40960 ? 40960 : b.Length - (i * 40960); byte[] temp = new byte[zz]; Array.Copy(b, i * 40960, temp, 0, zz); tcpClient.Client.Send(temp); //分割发送...... System.Threading.Thread.Sleep(1); } } } catch (Exception ee) { IsOnline = false; CloseConnect(); if (TimeOutEvent != null) { TimeOutEvent(); } SendStringCheck(command, text); if (ErrorMessageEvent != null) { ErrorMessageEvent(9, "send:" + ee.Message); } return(false); } // tcpc.Close(); return(true); }
public bool SendByteCheck(byte command, byte[] text) { try { //byte[] sendb = text; //byte[] lens = MyGameClientHelper.ConvertToByteList(sendb.Length); //byte[] b = new byte[2 + lens.Length + sendb.Length]; //b[0] = command; //b[1] = (byte)lens.Length; //lens.CopyTo(b, 2); //sendb.CopyTo(b, 2 + lens.Length); byte[] b = MyGameClientHelper.CodingProtocol(command, text); int count = (b.Length <= 40960 ? b.Length / 40960 : (b.Length / 40960) + 1); if (count == 0) { tcpClient.Client.Send(b); } else { for (int i = 0; i < count; i++) { int zz = b.Length - (i * 40960) > 40960 ? 40960 : b.Length - (i * 40960); byte[] temp = new byte[zz]; Array.Copy(b, i * 40960, temp, 0, zz); tcpClient.Client.Send(temp); System.Threading.Thread.Sleep(1); // Loom.WaitForNextFrame(10); // Loom.WaitForSeconds(0.001f); } } } catch (Exception ee) { IsOnline = false; CloseConnect(); if (TimeOutEvent != null) { TimeOutEvent(); } SendByteCheck(command, text); if (ErrorMessageEvent != null) { ErrorMessageEvent(9, "send:" + ee.Message); } return(false); } // tcpc.Close(); return(true); }