StructureToByteArrayEndian() public static method

public static StructureToByteArrayEndian ( object obj ) : byte[]
obj object
return byte[]
    public void SendMsg(NFrame.NFGUID xID, NFMsg.EGameMsgID unMsgID, MemoryStream stream)
    {
        if (NFStart.Instance.bDebugMode)
        {
            return;
        }

        NFMsg.MsgBase xData = new NFMsg.MsgBase();
        xData.player_id = NFToPB(xID);
        xData.msg_data  = stream.ToArray();

        MemoryStream body = new MemoryStream();

        Serializer.Serialize <NFMsg.MsgBase>(body, xData);

        MsgHead head = new MsgHead();

        head.unMsgID   = (UInt16)unMsgID;
        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);

        xNet.mxClient.SendBytes(sendBytes);

        string strTime = DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second;
        string strData = "S***:" + strTime + " MsgID:" + head.unMsgID + " Len:" + head.unDataLen;

        xNet.mxListener.aMsgList.Add(strData);
    }
Example #2
0
    public override void SendMsg(MsgHead head, byte[] bodyByte)
    {
        head.unDataLen = (UInt32)bodyByte.Length + (UInt32)ConstDefine.AF_PACKET_HEAD_SIZE;

        byte[] headByte = StructureTransform.StructureToByteArrayEndian(head);


        byte[] sendBytes = new byte[head.unDataLen];
        headByte.CopyTo(sendBytes, 0);
        bodyByte.CopyTo(sendBytes, headByte.Length);

        mxClient.SendBytes(sendBytes);

        string strTime = DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second;
        string strData = "S***:" + strTime + " MsgID:" + head.unMsgID + " Len:" + head.unDataLen;

        mReciveaMsgList.Add(strData);
    }