/// <summary> /// 发送数据(握手) /// </summary> /// <param name="state">发送对像</param> public static void SendHandshake(Kernel.AsynTCPClient state) { using (MemoryStream ms = new MemoryStream()) { using (BinaryWriter bw = new BinaryWriter(ms)) { byte ver = 1; short cmd1 = CommCmd.Handshake; short cmd2 = ErrCommon.Success; //0; int packagelength = 0; bw.Write(ver); bw.Write(cmd1); bw.Write(cmd2); bw.Write(packagelength); bw.Flush(); if (state.Connected) { state.BeginSend(ms.ToArray()); if (cmd1 != CommCmd.Handshake) { Commonality.ConsoleManage.Write(Commonality.ErrorLevel.Response, "Client Send Data Success", "CMD=" + cmd1.ToString() + " " + "BACKCODE=" + cmd2.ToString()); } } else { Commonality.ConsoleManage.Write(Commonality.ErrorLevel.Response, "CommonFunction>>TcpClientSend>>", "TCP Client Disconnect"); } } } }
/// <summary> /// TCP客户端发送数据Gzip不压缩 /// </summary> /// <param name="_obj"></param> public static void UnGzipTcpClientSend(object _obj) { Hashtable _hashtable_Package = (Hashtable)_obj; try { Kernel.AsynTCPClient tcpClient = (Kernel.AsynTCPClient)_hashtable_Package["1"]; using (MemoryStream ms = new MemoryStream()) { using (BinaryWriter bw = new BinaryWriter(ms)) { byte[] ResultByte = null; ResultByte = (byte[])_hashtable_Package["4"]; byte ver = 1; short cmd1 = (short)_hashtable_Package["2"]; short cmd2 = (short)_hashtable_Package["3"]; int packagelength = 0; if (ResultByte != null) { packagelength = ResultByte.Length; } bw.Write(ver); bw.Write(cmd1); bw.Write(cmd2); bw.Write(packagelength); if (packagelength > 0) { bw.Write(ResultByte); } bw.Flush(); if (tcpClient.Connected) { tcpClient.BeginSend(ms.ToArray()); if (cmd1 != CommCmd.Handshake) { Commonality.ConsoleManage.Write(Commonality.ErrorLevel.Response, "Client Send Data Success", "CMD=" + cmd1.ToString() + " " + "BACKCODE=" + cmd2.ToString()); } } else { Commonality.ConsoleManage.Write(Commonality.ErrorLevel.Response, "CommonFunction>>TcpClientSend>>", "TCP Client Disconnect"); } } } } catch { return; } finally { _hashtable_Package.Clear(); ////GC.Collect(); } }