【发布时间】:2012-02-29 01:19:13
【问题描述】:
我想在客户端和服务器之间发送命令和数据。
我有三个项目:
- 客户
- 服务器
- Common - 这里我放了公共类和网络抽象层
我正在使用以下数据结构进行客户端和服务器之间的通信
public class Packet<T>
{
public string Name { get; set; }
public string From { get; set; }
public string To { get; set; }
public PacketType PacketType { get; set; }
public T Container { get; set; }
public Packet()
{
}
public Packet(string name, PacketType packetType, T container)
{
Name = name;
PacketType = packetType;
Container = container;
}
}
public enum PacketType
{
Command,
Data
}
如果我需要发送有关文件的信息,我只需创建一个具有必要结构CreatePacket<FilesInfo>(filesInfo) 的数据包,然后对其进行序列化并将其发送到客户端\服务器。
但是如何在接收端反序列化数据?我不知道数据包是什么对象类型。有没有其他方法或图书馆或其他东西可以解决我的问题?此外,我不想使用 WCF,因为我的应用程序应该在安装了 .NET 2.0 的机器上运行。
【问题讨论】:
标签: c# .net serialization client-server deserialization