I have a UDP server that I have being trying to send structures using send() method.. No luck so far…
This is what I am using:
H,G are structures…
sender side:
IFormatter formatter = new BinaryFormatter();
MemoryStream stream = new MemoryStream();
formatter.Serialize(stream, H);
Byte[] buffer = stream.ToArray();
stream.Close();
and on the receiver side:
IFormatter formatter = new BinaryFormatter();
Stream s = new MemoryStream(buffer.Data);
ClientAnswerStruct G = (ClientAnswerStruct)formatter.Deserialize(s);
s.Close();
MessageBox.Show(G.name);
But I get this error:
Unable to find assembly 'UdpClientSample, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
‘UdpClientSample’ happens to be the title of the client program that is sending the data to the server… So I’m wondering if it takes more than serialization to be able so send a structure through UDP connection?
Is there a breakthrough out there that explains what Iamamac says?
I didn’t see the whole code, but I guess the server and client is two different executable files, and the
ClientAnswerStructclass is defined twice in both sides. When the receiver deserialize the data, it tries to reconstruct aClientAnswerStructobject but can not find its definition (Notice that it is defined on the sender’s side. Although on the receiver’s side there is a class namedClientAnswerStruct, but they are not the same).The right way to do this is define the
ClientAnswerStructclass in a standalone class library, and let the server and client code include it (‘add reference’ in C# terminology).