abood assaf
abood assaf

Reputation: 9

Asynchronous Sockets Serialization & Deserialization

I have a problem in receiving an object from my client which is written in Java. am 100% sure of my client code and it's good. but when i try to receive from my C# Asynchronous Server several errors come above i think it's because the stream which i really don't know how to get it

int iRx = socketData.m_currentSocket.EndReceive(asyn);
byte[] receivedData = socketData.dataBuffer;
MemoryStream memStream = new MemoryStream();
BinaryFormatter binForm = new BinaryFormatter();
memStream.Write(receivedData, 0, receivedData.Length);
memStream.Seek(0, SeekOrigin.Begin);
UserData usdata = (UserData)binForm.Deserialize(memStream);

Upvotes: 0

Views: 391

Answers (1)

Peter Ritchie
Peter Ritchie

Reputation: 35869

What is serialized by Java will be entirely different than what the built-in .NET serializers do. You'll have to know the format of the stream and manually deserialize a byte at time.

E.g. if you serialize an int in .NET, it serializes a 7-bit encoded value. If you serialize a custom type with BinaryFormatter, it includes the strong name of the type in the stream--clearly not what Java would do.

You might want to consider a third-party serializer/deserializer that works in Java and .NET. For example http://woxserializer.sourceforge.net/

Upvotes: 1

Related Questions