我正在使用 MRIM(Mail.Ru 代理)协议。MRIM 是一个二进制协议,所以为了使数据二进制,我使用 BinaryWriter 类。这是代码:
private byte[] CreateMrimPacket(ulong message)
{
byte[] binaryData;
using (MemoryStream ms = new MemoryStream())
{
using (BinaryWriter bw = new BinaryWriter(ms))
{
bw.Write(CS_MAGIC); //CS_MAGIC is a constant that doesn't equal 0
bw.Write(PROTO_VERSION); //Same thing
bw.Write((ulong)SeqCounter);
bw.Write(message);
bw.Write((ulong)0);
bw.Write((ulong)0);
bw.Write((ulong)0);
bw.Write((ulong)0);
bw.Write((ulong)0);
bw.Write((ulong)0);
bw.Write((ulong)0);
binaryData = new byte[ms.Length];
ms.Read(binaryData, 0, binaryData.Length);
}
}
return binaryData;
}
这个函数返回字节数组,但所有的值都是0。
请帮我解决这个问题。
提前致谢