C# send/receive Collections using protobuf-net + sockets example

家住魔仙堡 提交于 2019-12-11 20:37:52

问题


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; }
    }
}

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


回答1:


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.

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).



来源:https://stackoverflow.com/questions/16759334/c-sharp-send-receive-collections-using-protobuf-net-sockets-example

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!