这是我结构的定义
public struct SPMSifHdr
{
public UInt32 ui32Synch1;
public UInt32 ui32Synch2;
public ushort ui16Version;
public UInt32 ui32Cmd;
public UInt32 ui32BodySize;
};
struct SPMSifReturnKcdLclMsg
{
public SPMSifHdr hdr1;
public char ff;
public char[] Dta;
public bool Debug;
public char[] szOpId;
public char[] szOpFirst;
public char[] szOpLast;
}
如何将struct SPMSifReturnKcdLclMsg
转换为通过tcp / ip发送的字节数组?
原谅我的语言,我不能很好地使用英语:p
答案 0 :(得分:3)
Socket socket = OpenSocket();
using (var stream = new NetworkStream(socket))
{
var formatter = new BinaryFormatter();
formatter.Serialize(stream, obj);
}
修改强>
忘了提一下你的结构应该标记为Serializable