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发送它。
此外,即使 mSteam 的值为 3024,BinaryReader 指针似乎也保持在 0
由于您刚刚写入了 MemoryStream,因此指针位于没有要读取的内容的末尾。 在尝试从中读取之前,将位置重置回 0(零(:
mStream.Position = 0