Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VB.net跨网络序列化_Vb.net_Serialization_Tcpclient_Tcplistener - Fatal编程技术网

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