【发布时间】:2010-12-30 09:32:19
【问题描述】:
我有一个 UDP 服务器,我正在尝试使用 send() 方法发送结构.. 到目前为止没有运气...
这是我正在使用的:
H,G 是结构...
发送方:
IFormatter formatter = new BinaryFormatter();
MemoryStream stream = new MemoryStream();
formatter.Serialize(stream, H);
Byte[] buffer = stream.ToArray();
stream.Close();
在接收方:
IFormatter formatter = new BinaryFormatter();
Stream s = new MemoryStream(buffer.Data);
ClientAnswerStruct G = (ClientAnswerStruct)formatter.Deserialize(s);
s.Close();
MessageBox.Show(G.name);
但我收到此错误:
Unable to find assembly 'UdpClientSample, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
'UdpClientSample'恰好是向服务器发送数据的客户端程序的标题......所以我想知道是否需要序列化才能通过 UDP 连接发送结构?
那里有什么突破可以解释 Iamamac 所说的话吗?
【问题讨论】:
-
发送类是什么意思?你想序列化它并通过远程发送它吗?
-
@Y_Y:在您了解类和实例之间的区别之前,您可能要考虑不要这样做。
-
您可以尝试将其序列化为字符串格式,如果需要加密并发送。