mariano_donati
Active member
- Joined
- Nov 30, 2005
- Messages
- 41
- Programming Experience
- Beginner
Hi everybody, I'm triying to send a serialized object through a socket. I have this application Client/Server, wich works sending classes from and to the server. Each class represent a event, with certain info about it. For example, I have a MessageClass wich also has a few properties like Data(), IdFrom(), IdTo(). I want to send it to the server, the server analize the relevant property (in this case, IdTo() property), and redirect the class to the client wich its Id = IdTo property.
This is the important function in the server application:
Private Function DeserializeBytes(ByVal B() As Byte) As Message
Dim M As New MemoryStream(B)
Dim Formatter As New BinaryFormatter()
Return CType(Formatter.Deserialize(M), Message)
End Function
B() param, is a array of bytes that client sends to the server. This array contains the serialized object. At client application I do this:
Private Function GetSerializedBytes(ByVal E As Message) As Byte()
Dim Formatter As New BinaryFormatter()
Dim S As New MemoryStream()
Formatter.Serialize(S, E)
Dim BinaryReader As New BinaryReader(S)
Dim Buffer() As Byte
Buffer = New Byte(S.Length) {}
BinaryReader.Read(Buffer, 0, S.Length)
Return Buffer
End Function
This function returns an array of bytes with the serialized object (at least I suppose so) and it's the array wich is sent from the client to the server.
When server application executes the line wich is marked with the frown face, it throw a System.Runtime.Serialization.SerializationException at mscorlib.dll.
Can you see any error here?.
I'd be really greateful if you can help me out with this.
Sorry for my english.
Regards.
This is the important function in the server application:
Private Function DeserializeBytes(ByVal B() As Byte) As Message
Dim M As New MemoryStream(B)
Dim Formatter As New BinaryFormatter()
Return CType(Formatter.Deserialize(M), Message)
End Function
B() param, is a array of bytes that client sends to the server. This array contains the serialized object. At client application I do this:
Private Function GetSerializedBytes(ByVal E As Message) As Byte()
Dim Formatter As New BinaryFormatter()
Dim S As New MemoryStream()
Formatter.Serialize(S, E)
Dim BinaryReader As New BinaryReader(S)
Dim Buffer() As Byte
Buffer = New Byte(S.Length) {}
BinaryReader.Read(Buffer, 0, S.Length)
Return Buffer
End Function
This function returns an array of bytes with the serialized object (at least I suppose so) and it's the array wich is sent from the client to the server.
When server application executes the line wich is marked with the frown face, it throw a System.Runtime.Serialization.SerializationException at mscorlib.dll.
Can you see any error here?.
I'd be really greateful if you can help me out with this.
Sorry for my english.
Regards.