Where there is a dream ,there is hope

  C++博客 :: 首页 :: 联系 :: 聚合  :: 管理
  64 Posts :: 0 Stories :: 8 Comments :: 0 Trackbacks

常用链接

留言簿(1)

我参与的团队

搜索

  •  

最新评论

阅读排行榜

评论排行榜

C#结构体定义:
[Serializable]
    
struct DR2DE_Send
    
{
        
public UInt32 AA;
        
public UInt32 BB;
        
public UInt16 CC;   //! Encryption method.
        public UInt16 DD;            //! message version  // used to decide message version.
        public UInt32 EE;           //! message id.
        public UInt32 FF;          //! Message order. it is a increseable integer and set when checkEncrypt called and when ReturnMessage is set.
        public Byte GG;
        
public Byte LL;
        
public char[] MM;
    }

序列化操作:
byte[] sendMsg = new byte[1024];
            BinaryFormatter bf 
= new BinaryFormatter();
            MemoryStream stream 
= new MemoryStream();
            DR2DE_Send dr2deMessage;
            dr2deMessage.AA
= (UInt32)(0);
            dr2deMessage.BB
= (UInt16)(0);
            dr2deMessage.CC
=(UInt32)(0);
            dr2deMessage.DD
= (UInt16)(0);
            dr2deMessage.EE
= "Hello".ToCharArray();
            dr2deMessage.FF
= 40010;
            dr2deMessage.GG
= (UInt32)(22 + dr2deMessage.data.Length);
            dr2deMessage.HH
= 1;
            dr2deMessage.II
= 1;

            bf.Serialize(stream, dr2deMessage);
            sendMsg 
= stream.ToArray();
sendMsg就可以放到sock中发送出去了。
posted on 2010-11-24 10:53 IT菜鸟 阅读(1226) 评论(0)  编辑 收藏 引用 所属分类: C#

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理