Java - .Net object interchange, not web-based

前端 未结 3 1782
醉话见心
醉话见心 2021-01-25 06:32

I have a client-server system implemented in C#, and the client and server exchange .Net objects via serialization / deserialization and communicating via TCP/IP. This runs on a

3条回答
  •  佛祖请我去吃肉
    2021-01-25 07:06

    SO user "default locale" should get the honor for this, but he/she has only answered via a comment. So just to make it very clear what my choice was I'll answer my own question.

    I've decided to go with Google Protocol Buffers, which in my opinion has much better support for moving objects back and forth between Java and .Net than JSON. Because I have a lot of experience with C#, and a lot of existing C#-defined classes, I've selected Marc Gravell's protobuf-net program for the .Net end, and Google's own support for the Android end (no - see edit). This implies that I'm defining the objects in C#, not in .proto files - protobuf-net generates the .proto files from which I then generate the Java code.

    Incidentally, as the transport mechanism I'm using a little-known program called naga on the Android end. http://code.google.com/p/naga/ Naga seems to work fine, and is well-documented and has sample programs, and should be better known in my opinion.

    EDIT:

    OK, I've got it working now to my satisfaction. Here's what I'm using:

    Google Protocol buffers as the interchange format: https://developers.google.com/protocol-buffers/

    Marc Gravell's protobuf-net at the C# end: http://code.google.com/p/protobuf-net/

    A program called called protostuff at the Java end: http://code.google.com/p/protostuff/

    (I prefer protostuff to the official Google Java implementation of protocol buffers due to Google's implementation being based on the Java objects being immutable.)

    Actually, I'm not using pure protocol buffers as the interchange format - I prefix the data with the name of the (outermost) class being transmitted. This makes the data self-identifying for deserializing at the other end.

提交回复
热议问题