VB.net 跨网络序列化
VB.net serialization across a network
我正在尝试通过网络序列化 class,但我不断收到以下错误。
System.Runtime.Serialization.SerializationException: 'End of Stream encountered before parsing was completed.'
我看到有几个线程建议将网络流转换为内存流以允许您将位置设置为 0,但这对我不起作用。
我的密码是
'Receiver
Private Sub ReceivingMethod()
Dim f As BinaryFormatter = New BinaryFormatter()
Dim msg As clsMessage
msg = f.Deserialize(TCPClient.GetStream())
ProcessMessage(msg)
Threading.Thread.Sleep(50)
End Sub
.
'Sender
Private Sub SendingMethod()
do while MessageQueue.count > 0
'Get the first message from the queue
Dim msg As clsMessage = MessageQueue(0)
Dim f As BinaryFormatter = New BinaryFormatter()
f.Serialize(TCPClient.GetStream(), msg)
MessageQueue.Remove(msg)
End If
Threading.Thread.Sleep(50)
Loop
End Sub
如有任何帮助,我们将不胜感激。
我发现 protobuf-net 很容易实现,而且比使用二进制格式化程序容易得多。我最初以为 'how hard could it be' 但后来就明白了为什么要创建外部序列化了。
谢谢大家
我正在尝试通过网络序列化 class,但我不断收到以下错误。
System.Runtime.Serialization.SerializationException: 'End of Stream encountered before parsing was completed.'
我看到有几个线程建议将网络流转换为内存流以允许您将位置设置为 0,但这对我不起作用。
我的密码是
'Receiver
Private Sub ReceivingMethod()
Dim f As BinaryFormatter = New BinaryFormatter()
Dim msg As clsMessage
msg = f.Deserialize(TCPClient.GetStream())
ProcessMessage(msg)
Threading.Thread.Sleep(50)
End Sub
.
'Sender
Private Sub SendingMethod()
do while MessageQueue.count > 0
'Get the first message from the queue
Dim msg As clsMessage = MessageQueue(0)
Dim f As BinaryFormatter = New BinaryFormatter()
f.Serialize(TCPClient.GetStream(), msg)
MessageQueue.Remove(msg)
End If
Threading.Thread.Sleep(50)
Loop
End Sub
如有任何帮助,我们将不胜感激。
我发现 protobuf-net 很容易实现,而且比使用二进制格式化程序容易得多。我最初以为 'how hard could it be' 但后来就明白了为什么要创建外部序列化了。
谢谢大家