VB.net跨网络序列化
我正试图通过网络序列化一个类,但我一直遇到以下错误VB.net跨网络序列化,vb.net,serialization,tcpclient,tcplistener,Vb.net,Serialization,Tcpclient,Tcplistener,我正试图通过网络序列化一个类,但我一直遇到以下错误 System.Runtime.Serialization.SerializationException: 'End of Stream encountered before parsing was completed.' 我看到一些线程建议将网络流转换为内存流,以允许您将位置设置为0,但这对我不起作用 我的代码是 'Receiver Private Sub ReceivingMethod() Dim f As BinaryForm
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
任何帮助都将不胜感激。我发现protobuf-net很容易实现,而且比使用二进制格式化程序容易得多。我最初认为“这可能有多难”,但后来很明显,为什么要创建外部序列化 谢谢大家
'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