/// <summary> /// 发送SOCKET消息 /// </summary> public void SendMsg(int uMsgID, ByteBuffer buffer) { NFMsg.MsgBase xData = new NFMsg.MsgBase(); xData.player_id = Util.NFToPB(mMainID); ByteBuffer newbuffer = new ByteBuffer(buffer.ToBytes()); xData.msg_data = newbuffer.ReadBytes(); MemoryStream body = new MemoryStream(); Serializer.Serialize <NFMsg.MsgBase>(body, xData); MsgHead head = new MsgHead(); head.unMsgID = (UInt16)uMsgID; head.unDataLen = (UInt32)body.Length + (UInt32)ConstDefine.NF_PACKET_HEAD_SIZE; byte[] bodyByte = body.ToArray(); byte[] headByte = StructureTransform.StructureToByteArrayEndian(head); byte[] sendBytes = new byte[head.unDataLen]; headByte.CopyTo(sendBytes, 0); bodyByte.CopyTo(sendBytes, headByte.Length); SocketClient.SendMessage(sendBytes); buffer.Close(); newbuffer.Close(); }