본문 바로가기
프로그래밍

C#에서의 Socket 통신시 byte배열로 변환하기 [패킷화 하기]

by 건우아빠유리남편 2010. 5. 25.
반응형

        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);
        }

반응형

댓글