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
所以我有这段代码,我要做的是发送一个序列化的数据集。
因此,我将序列化的数据集放入一个memorystream中,并将其转换为一个字节数组,以便用binarywritter发送它。
此外,即使msteam的值为3024,binaryreader指针似乎仍保持在0
最佳答案
由于您刚刚写入了memoryStream,所以指针位于没有可读取内容的末尾。在尝试读取之前,将位置重置为0(零):
mStream.Position = 0