问题
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