private void SendMessage(TcpChannelContext context, byte[] data) { byte[] body = new byte[sizeof(Int32) + data.Length]; BitConverter.GetBytes(data.Length).CopyTo(body, 0); data.CopyTo(body, 4); if (context == null) { return; } context.SendMessage(body, 0, body.Length); }
private void ProcessSendMessage(byte[] data) { //byte[] body = new byte[data.Length - 1]; //Array.Copy(data, 1, body, 0, body.Length); long id = BitConverter.ToInt64(data, 1); Console.WriteLine("ProcessSendMessage:" + id); GCHandle gc = GCHandle.FromIntPtr(new IntPtr(id)); Console.WriteLine("ProcessSendMessage OK"); TcpChannelContext context = gc.Target as TcpChannelContext; if (context == null) { return; } //将消息转发给MainChannel context.SendMessage(data, sizeof(Int64) + 1, data.Length - sizeof(Int64) - 1); }