SyncLock _client.GetStream
Dim bArray() As Byte
Dim bWriter As New BinaryWriter(_client.GetStream)
Dim bf As New BinaryFormatter
Dim mStream As New MemoryStream
bf.Serialize(mStream, dSet)
'Send tagIdentifier
bWriter.Write(bTag)
'Send the Object length
bWriter.Write(CInt(mStream.ToArray.Length))
'It's not null, value of 3024
Console.WriteLine("Mstream : " & mStream.ToArray.Length)
'Initialize the BinaryReader
Dim bReader As New BinaryReader(mStream)
Do
bArray = bReader.ReadBytes(1024)
''''''''''''''bArray stay at 0'''''''''''''''
bWriter.Write(bArray)
Loop While bArray.Length = 1024
bWriter.Flush()
End SyncLock所以我有这个代码,我想要做的是发送一个序列化的数据集。
因此,我将序列化的dSet放在一个memoryStream中,并将其转换为一个字节数组,以将其与BinaryWritter一起发送。
此外,即使BinaryReader指针的值为3024,mSteam指针似乎仍保持在0。
发布于 2013-11-20 20:47:51
因为您刚刚写到MemoryStream,指针就在没有什么可读的末尾。在尝试读取该位置之前,将其重置为0(零):
mStream.Position = 0https://stackoverflow.com/questions/20106355
复制相似问题