[.NET] Socket BinaryFormatter MemoryStream

楼主: a0tim (~TIM~)   2015-10-30 01:16:48
应用程式专案
目的:
送SQL查询字串给server,收回传序列化的DataTable再反序列化
client 接收及反序列化程式码:
Case "DATATABLE" ' 承接回传的DB查询
Dim i = clientSocket.Receive(byteData)
Dim bf As New BinaryFormatter()
Dim ms As New MemoryStream(65534)
ms.Write(byteData, 0, i)
ms.Flush()
Thread.Sleep(200)
While i = 8192
i = clientSocket.Receive(byteData)
If i > 0 Then
ms.Write(byteData, 0, i)
ms.Flush()
Thread.Sleep(200)
End If
End While
ms.Seek(0, SeekOrigin.Begin)
resultDataTable = bf.Deserialize(ms)
请教各位前辈
只要我不加上Thread.Sleep让MemoryStream在write后等待一段时间
最后在反序列化的时候就会出错 在完成剖析之前已达资料流末端
这是为什么?
小弟百思不得其解
楼主: a0tim (~TIM~)   2015-10-30 01:23:00
ps. 不等待的话,最后的ms.length会少

Links booklink

Contact Us: admin [ a t ] ucptt.com