欲在C#种实现以下雷同功能:VC++得实现:
//报头
*(unsigned int*)(buf)=htonl(m_nSeq++); //包序号
*(unsigned short*)(buf+4)=htons(TYPE_DZJP); //业务类型
*(unsigned int*)(buf+6)=htonl(COM_LOGIN); //命令类型
*(unsigned int*)(buf+10)=htonl(20); //包体长度
*(unsigned int*)(buf+14)=htonl(777); //银行IDC#得实现:
private byte[] buf; //整个包得数据
buf=new byte[58];
buf=BitConverter.GetBytes(IPAddress.HostToNetworkOrder(m_nSeq++)); //包序号4字节整数
buf[4]=BitConverter.GetBytes(IPAddress.HostToNetworkOrder(TYPE_YQDZ)); //TYPE_YQDZ为2字节短整数这里不行,说是:
D:\Work\YQDZ\YQDZ\CCSock.cs(181): 无法将类型“byte[]”隐式转换为“byte”
怎么写啊??谢谢
//报头
*(unsigned int*)(buf)=htonl(m_nSeq++); //包序号
*(unsigned short*)(buf+4)=htons(TYPE_DZJP); //业务类型
*(unsigned int*)(buf+6)=htonl(COM_LOGIN); //命令类型
*(unsigned int*)(buf+10)=htonl(20); //包体长度
*(unsigned int*)(buf+14)=htonl(777); //银行IDC#得实现:
private byte[] buf; //整个包得数据
buf=new byte[58];
buf=BitConverter.GetBytes(IPAddress.HostToNetworkOrder(m_nSeq++)); //包序号4字节整数
buf[4]=BitConverter.GetBytes(IPAddress.HostToNetworkOrder(TYPE_YQDZ)); //TYPE_YQDZ为2字节短整数这里不行,说是:
D:\Work\YQDZ\YQDZ\CCSock.cs(181): 无法将类型“byte[]”隐式转换为“byte”
怎么写啊??谢谢
----
这个得到的是一个byte么?
那么应该
byte []temp=BitConverter.GetBytes(IPAddress.HostToNetworkOrder(TYPE_YQDZ));
buf[4]=temp[0];
buf[5]=temp[1];
如果用socket发,你的是上层的,等到了下曾照样再加上包头,你所谓的包头就成了数据信息了