使用Protobuf-net +套接字示例的C#发送/接收集合 [英] C# send/receive Collections using protobuf-net + sockets example
问题描述
我正在寻找有关如何使用protobuf-net序列化和套接字连接在两台计算机之间传输集合的完整示例。我成功找到的只是代码的各个部分,没有人无法向像我这样的菜鸟解释如何结合所有这些内容。在.proto文件之后:
I'm looking for complete example of how to transfer collections between 2 machines by using protobuf-net serialization and sockets connection. All I succeed to find is separate parts of code and no one of them can't explain to the noob like me how to combine all this stuff. Following the .proto file:
using System;
using ProtoBuf;
namespace Proto.Transaction
{
[Serializable]
[ProtoContract]
public class Transaction
{
[ProtoMember(1)]
public int Type { get; set; }
[ProtoMember(2)]
public int AgentID { get; set; }
[ProtoMember(3)]
public string TransactionName { get; set; }
[ProtoMember(4)]
public string ScriptName { get; set; }
[ProtoMember(5)]
public DateTime StartTime { get; set; }
[ProtoMember(6)]
public double TransactionLength { get; set; }
}
}
最后,我必须将其作为可观察的集合接收并将其设置为DataSet(以便将其保存为XML并将其呈现在DataGrid中)。感谢您的帮助和/或链接到网络中适当材料的链接。
问候
Finally, I have to receive this as Observable Collection and set it as DataSet(in order to save it as XML and present it in DataGrid). I'll appreciate any help and/or links to an appropriate materials in the net. Regards
推荐答案
在最基本的级别中,您可以查看下面的示例 QuickStart / 3 Sockets.cs 。这里的关键点是如果您在原始套接字级别上工作,则需要在消息之间添加某种分区(因为TCP只是一个流)。该示例通过使用 * WithLengthPrefix
方法完成此操作。
At the most basic level, you can look at the example under QuickStart/3 Sockets.cs. The key point here is that if you are working at the raw sockets level, you will need to add some kind of partitioning between messages (because TCP is just a stream). The sample does this by using the *WithLengthPrefix
methods.
但是,在许多情况下,您可以使用已经包含消息分区的预卷式RPC /消息传递实现;在这种情况下,您不需要使用 * WithLengthPrefix
方法(尽管欢迎这样做)。
In many cases, however, you may be able to use a pre-rolled RPC / message-passing implementation that already includes message partitioning; in that case you do not need to use the *WithLengthPrefix
methods (although you are welcome to do so).
这篇关于使用Protobuf-net +套接字示例的C#发送/接收集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!