상세 컨텐츠

본문 제목

Socket 통신시 byte배열로 변환하기 [패킷화 하기]

C#

by 탑~! 2011. 5. 13. 09:42

본문


public static void SetPacket(uint uCommand, uint uData , ref byte[] btBuf, ref uint uLen)
        {
            BitConverter.GetBytes(STARTCODE).CopyTo(btBuf, uLen);
            uLen += sizeof(uint);


            BitConverter.GetBytes(SESSIONNO_UNKNOWN).CopyTo(btBuf, uLen);
            uLen += sizeof(uint);

            const uint DATALENGTH = sizeof(uint) + sizeof(uint);     //CMD + DATA length
           
            //btBuf.SetValue(DATALENGTH, sizeof(uint) + uLen);
            BitConverter.GetBytes(DATALENGTH).CopyTo(btBuf, uLen);
            uLen += sizeof(uint);

            BitConverter.GetBytes(uCommand).CopyTo(btBuf, uLen);
            uLen += sizeof(uint);

            BitConverter.GetBytes(uData).CopyTo(btBuf, uLen);
            uLen += sizeof(uint);

            BitConverter.GetBytes(ENDCODE).CopyTo(btBuf, uLen);
            uLen += sizeof(uint);
        }


 

관련글 더보기